droibit / react-native-custom-tabs

Chrome Custom Tabs for React Native.
https://www.npmjs.com/package/react-native-custom-tabs
Apache License 2.0
187 stars 108 forks source link

Close browser programmatically #22

Open RichardLindhout opened 6 years ago

RichardLindhout commented 6 years ago

Nice library!

We are using your library on Android for 0Auth login with different providers. When the user is authenticated we want to programmatically close the chrome tabview within our app.

Is this currently possible?

ataillefer commented 6 years ago

Nope, just navigate to another screen of your app once you've been redirected by the OAuth flow. Something like:

  componentDidMount() {
    Linking.addEventListener('url', this._authorize);
  }

  async _authorize(options) {
     // handle url with options.url, for example parse the parameters to get the authorization code
     // navigate to your app's home screen
  }
RichardLindhout commented 6 years ago

I get that. But the user is still on the browser screen right?

ataillefer commented 6 years ago

Well no, if you navigate to another screen of your app then you are no more on the Chrome Custom Tab.

ianataffinity commented 6 years ago

@ataillefer and if you want the user to stay on the screen that launched the new tab? Is there a way to close it?

ataillefer commented 6 years ago

Close it, technically, no, but in the _authorize callback from the sample given in https://github.com/droibit/react-native-custom-tabs/issues/22#issuecomment-351932486, just use setState to rerender the current screen with any React Native components.

NicolasBonduel commented 6 years ago

Hi @ataillefer I'm trying to do that, however the listener is not triggered until I close the tab myself. I'm using Wix's navigation if that helps.

dev6james commented 5 years ago

I have this issue. You can't navigate in the background with v1 (maybe v2 too?) in the Wix navigation library. It just flat out fails. I dug into that a while back and found out the current activity reference they have is null when in the background and their navigation just noops. (enjoy - https://github.com/wix/react-native-navigation/blob/v1/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java)

When the custom tab is open, the app is in 'background' state, thus you can't navigate if using Wix (v1 at least). However, it does fire the 'appLaunched' event and you can call 'startApp' again. Unfortunately though, that means you'd have no access to the parameters from the redirect.

FYI forceCloseOnRedirection does nothing in this case.

I am surprised a bigger fuss hasn't been made about this considering RNN is one of the most popular React Native navigation libraries.

aithashi commented 3 years ago

Hi Devs.. Anyone found any workaround to close custom tab once we redirect to our app? Thanks in advance