Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: detached view controllers #116

Open
mpht opened this issue May 20, 2020 · 3 comments
Open

iOS: detached view controllers #116

mpht opened this issue May 20, 2020 · 3 comments

Comments

@mpht
Copy link

mpht commented May 20, 2020

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)
    tns-core-modules@6.0.1
  • 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
Copy link
Author

mpht commented Jun 12, 2020

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 #98 (comment)

@Burgov
Copy link
Contributor

Burgov commented Jul 10, 2020

Thanks! This fixed it for me too

@alexziskind1
Copy link
Owner

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

Burgov added a commit to Burgov/nativescript-oauth2 that referenced this issue Aug 29, 2020
@Burgov Burgov mentioned this issue Aug 29, 2020
Burgov added a commit to Burgov/nativescript-oauth2 that referenced this issue Aug 29, 2020
Burgov added a commit to Burgov/nativescript-oauth2 that referenced this issue Aug 29, 2020
Burgov added a commit to Burgov/nativescript-oauth2 that referenced this issue Aug 29, 2020
alexziskind1 added a commit that referenced this issue Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants