nativescript-oauth2 icon indicating copy to clipboard operation
nativescript-oauth2 copied to clipboard

iOS: detached view controllers

Open mpht opened this issue 5 years ago • 3 comments

Please, tell us how to recreate the issue in as much detail as possible.

This only happens on iOS - Android works fine.

  1. Go do demo-angular.
  2. 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>
  1. 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 --version to fetch it) 6.5.0
  • Cross-platform modules: (check the 'version' attribute in the node_modules/tns-core-modules/package.json file in your project) [email protected]
  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the package.json file of your project)
"tns-android": {
    "version": "6.0.0"
},
"tns-ios": {
    "version": "6.0.1"
}

mpht avatar May 20 '20 12:05 mpht

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

mpht avatar Jun 12 '20 15:06 mpht

Thanks! This fixed it for me too

Burgov avatar Jul 10 '20 08:07 Burgov

Thanks for the sample code. If anyone wants to do a PR on this, that would be awesome!

alexziskind1 avatar Jul 10 '20 11:07 alexziskind1