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

Android - how to know when the browser was closed by user? #8

Closed
mlazari opened this issue Oct 4, 2018 · 5 comments
Closed

Android - how to know when the browser was closed by user? #8

mlazari opened this issue Oct 4, 2018 · 5 comments

Comments

@mlazari
Copy link
Contributor

mlazari commented Oct 4, 2018

I have an intent filter like this in my Android app:

<activity
        android:name=".MainActivity"
        ...
>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="myapp" android:host="test" />
        </intent-filter>
        ...
</activity>

If I open the browser a page that redirects to myapp://test the browser is dismissed and the result type is "cancel", which makes impossible to distinguish this situation from the situation when the user closed the browser manually.

props.openOAuthUrl(urlThatRedirectsToApp).then((result) => {
  console.log(result); // { type: 'cancel' }, but probably it should be { type: 'dismiss' } so I can know that the user did not close the browser manually
});

The promise is resolved with { type: 'cancel' } here when the browser activity is destroyed:

On iOS when the browser redirects to myapp://test the browser is not dismissed automatically. Instead I detect with Linking that the app was opened with that url, and close the browser from there, which I think is fine:

Linking.addEventListener('url', (url) => {
  InAppBrowser.close();
  console.log('URL: ', url);
});
@jdnichollsc
Copy link
Member

Check the documentation of the WebBrowser https://docs.expo.io/versions/latest/sdk/webbrowser#returns

If you want you can propose the change with a pull request to include that into the documentation too (README)

@mlazari
Copy link
Contributor Author

mlazari commented Oct 5, 2018

@jdnichollsc I'm not using Expo, but using this module this seems to be true only for iOS:

When the listener fires, you should call WebBrowser.dismissBrowser() -- it will not automatically dismiss when a deep link is handled.

On Android it's dismissed automatically, but the promise resolves with {type: 'cancel'} instead of {type: 'dismiss'}, no matter if I call InAppBrowser.close(); or not. On iOS it's resolved with {type: 'dismiss'} when it's closed with InAppBrowser.close();.

Here is a minimal example that reproduces the issue: https://github.com/mlazari/in-app-browser-my-app
And here is the difference between the behaviour on iOS and on Android:
android-vs-ios

@mlazari mlazari mentioned this issue Oct 5, 2018
@mlazari
Copy link
Contributor Author

mlazari commented Oct 5, 2018

@jdnichollsc I opened a pull request #9
Can you please review it? With that fix the result type is the same as on iOS.

@jdnichollsc
Copy link
Member

jdnichollsc commented Oct 8, 2018

@mlazari thanks for your excellent contribution and sorry for the delay!

@mlazari
Copy link
Contributor Author

mlazari commented Oct 8, 2018

@jdnichollsc No problem. Thanks.

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

2 participants