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

Add Ability to Close WebView #26

Open
one-adam-nolan opened this issue Feb 18, 2018 · 8 comments
Open

Add Ability to Close WebView #26

one-adam-nolan opened this issue Feb 18, 2018 · 8 comments

Comments

@one-adam-nolan
Copy link

This would be really helpful for OpenId Connect using a Hybrid Authorization Workflow. For my case, I launch to the external browser for login (Identity Server 4) and use the redirect with UrlHandler. If the server redirect is something like adams.app://authorized I want to programmatically be able to close the webview and pop back into the app.

I have a created a branch locally and have implemented the dismiss call for the SafariViewController (iOS) in the Demo app. Unfortunately, its been sometime since I have dealt with native Android; so I am not sure where to start there.

@alexmeia
Copy link

Hello @one-adam-nolan , I need exactly the same thing and I am interested in your implementation of the dismiss call for SafariViewController. Can you please provide a link to your branch? I checked this repository but I couldn't find the implementation. Thanks.

@one-adam-nolan
Copy link
Author

@alexmeia Sorry about not getting back with you sooner. I need to check my work computer to see if I still have that repo locally. At the time, I hadn't really used git and had some trouble setting up my fork.

@Aqu1nt
Copy link

Aqu1nt commented Jun 18, 2018

I'm using this plugin to implement an OAuth flow and ran into this issue aswell.
After some searching i found the following solution, which seems to work and close the SafariViewController.

This might help to implement the close() feature or for other people having the same issue.

import * as application from 'application';

// Only for IOS
const controller = application.ios.nativeApp.windows[0].rootViewController;
controller.dismissViewControllerAnimatedCompletion(true, () => {
  console.log('Safari dismissed')
});

@championswimmer
Copy link

thanks @Aqu1nt that works !!

@championswimmer
Copy link

@bradmartin I'll try to implement the same in Android, and if theres a reliable way to do both in Android and iOS, you can maybe add a method in the library itself that does it !

@triniwiz
Copy link
Collaborator

@championswimmer the lib is => here feel free to send a pr 😄

@championswimmer
Copy link

actually if launchMode is singleTop in Android, it automatically closes!

@alexmeia
Copy link

alexmeia commented Jul 21, 2018

Two months ago I was in a rush to make it close the advanced webview in iOS after login, and I did a little edit to the plugin to return the SFSafariViewController (or the AdvancedWebView in Android) when the method openAdvancedUrl is called. In this way, you can close the WebView calling the native methods (in my case, as @championswimmer said, this was needed only in iOS).

let advancedWebView: any;
advancedWebView = openAdvancedUrl(opts);

export function closeAdvancedWebView(animated: boolean) {
    // No need to manually close advancedWebView in Android.
    if (advancedWebView && platform.isIOS) {
        advancedWebView.dismissViewControllerAnimatedCompletion(animated, null);
    }
}

If this can be useful, you can see iOS the edit here: https://github.com/phoops/nativescript-advanced-webview/blob/master/advanced-webview.ios.ts#L79
Pretty same for Android.
I'm using our custom version as dependency in my projects, for now.

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

5 participants