react-native-custom-tabs icon indicating copy to clipboard operation
react-native-custom-tabs copied to clipboard

Close browser programmatically

Open RichardLindhout opened this issue 8 years ago • 8 comments

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?

RichardLindhout avatar Dec 14 '17 18:12 RichardLindhout

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
  }

ataillefer avatar Dec 15 '17 07:12 ataillefer

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

RichardLindhout avatar Dec 15 '17 19:12 RichardLindhout

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

ataillefer avatar Dec 18 '17 09:12 ataillefer

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

ianataffinity avatar Jan 05 '18 01:01 ianataffinity

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.

ataillefer avatar Jan 05 '18 09:01 ataillefer

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.

NicolasBonduel avatar Apr 19 '18 15:04 NicolasBonduel

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.

dev6james avatar Apr 10 '19 01:04 dev6james

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

aithashi avatar Apr 15 '21 07:04 aithashi