nativescript-oauth2
nativescript-oauth2 copied to clipboard
iOS: detached view controllers
Please, tell us how to recreate the issue in as much detail as possible.
This only happens on iOS - Android works fine.
- Go do demo-angular.
- Modify app.component.html to
<RadSideDrawer tkExampleTitle tkToggleNavButton>
<StackLayout tkDrawerContent>
<Label text="Menu 01"></Label>
</StackLayout>
<GridLayout tkMainContent>
<page-router-outlet></page-router-outlet>
</GridLayout>
</RadSideDrawer>
or even simpler
<GridLayout>
<page-router-outlet></page-router-outlet>
</GridLayout>
- Press login:
Presenting view controllers on detached view controllers is discouraged <UINavigationControllerImpl: 0x102818e00>.
Webview opens but nothing is shown
Workaround
You can create the following patch for tns-oauth-native-view-controller.ios.js and apply it using a hook. Please feel free to give input to that patch. Is this a possible solution or really just an ugly workaround?
Here is the patch file content:
--- node_modules/nativescript-oauth2/tns-oauth-native-view-controller.ios.js
+++ node_modules/nativescript-oauth2/tns-oauth-native-view-controller.ios.js
@@ -27,7 +27,15 @@
TnsOAuthLoginNativeViewController.prototype.openUrlWithParametersCompletion = function (fullUrl, frame) {
this.safariViewController = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(NSURL.URLWithString(fullUrl), false);
this.safariViewController.delegate = this;
- frame.ios.controller.presentViewControllerAnimatedCompletion(this.safariViewController, true, null);
+ if(frame.parent) {
+ let topmostParent = frame.parent;
+ while(topmostParent.parent) {
+ topmostParent = topmostParent.parent;
+ }
+ topmostParent.viewController.presentViewControllerAnimatedCompletion(this.safariViewController, true, null);
+ } else {
+ frame.ios.controller.presentViewControllerAnimatedCompletion(this.safariViewController, true, null);
+ }
};
TnsOAuthLoginNativeViewController.prototype.resumeWithUrl = function (url) {
var _this = this;
Make sure to check the demo app(s) for sample usage
Can be reproduced by a small modification to demo-angular app.component.html
<GridLayout>
<page-router-outlet></page-router-outlet>
</GridLayout>
Which platform(s) does your issue occur on?
- iOS
Please, provide the following version numbers that your issue occurs with:
- CLI: (run
tns --versionto fetch it)6.5.0 - Cross-platform modules: (check the 'version' attribute in the
node_modules/tns-core-modules/package.jsonfile in your project)[email protected] - Runtime(s): (look for the
"tns-android"and"tns-ios"properties in thepackage.jsonfile of your project)
"tns-android": {
"version": "6.0.0"
},
"tns-ios": {
"version": "6.0.1"
}
Just to have everything in one post: @imiskuf created a fork with my code and some deprecation fix - You can go check this out instead of using my patch.
@demolot you can try to use my forked repository (https://www.npmjs.com/package/nativescript-oauth2-forked). It contains the code from #116 and some deprecation fix
Originally posted by @imiskuf in https://github.com/alexziskind1/nativescript-oauth2/issues/98#issuecomment-640048046
Thanks! This fixed it for me too
Thanks for the sample code. If anyone wants to do a PR on this, that would be awesome!