proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.29k stars 218 forks source link

Is it possible to trigger a callback when the browser closes? #415

Closed aryella-lacerda closed 8 months ago

aryella-lacerda commented 1 year ago

Hello! Thanks for maintaining this project, it's been very helpful to our team. But we're stuck on a minor issue: is it possible to trigger a callback when the user closes out of the browser? 🤔

oddlyspaced commented 1 year ago

You can handle the BrowserResult promise for the cancel event, for deeplinking and successful callbacks i have a separate deeplink handler in my code that dismisses it. This is how I have been handling the success and failure situations in my code. Both approaches lead to closing of the browser

niteshagrawal commented 11 months ago

You can handle the BrowserResult promise for the cancel event, for deeplinking and successful callbacks i have a separate deeplink handler in my code that dismisses it. This is how I have been handling the success and failure situations in my code. Both approaches lead to closing of the browser

can you attach an example that how you are doing it? any help will be appreciated.

aryella-lacerda commented 11 months ago
  try {
    if (await InAppBrowser.isAvailable()) {
      const result = await InAppBrowser.open(url, {...});

      // when the users presses the cancel/close button 
      if (result.type === 'cancel') {
        onCancel(); 
      }

      // when you call the close() method
      if (result.type === 'dismiss') {
        onDismiss(); 
      }
    } else {
      Linking.openURL(url);
    }
  } catch (error) {
    console.log(error.message);
  }
niteshagrawal commented 11 months ago
  try {
    if (await InAppBrowser.isAvailable()) {
      const result = await InAppBrowser.open(url, {...});

      // when the users presses the cancel/close button 
      if (result.type === 'cancel') {
        onCancel(); 
      }

      // when you call the close() method
      if (result.type === 'dismiss') {
        onDismiss(); 
      }
    } else {
      Linking.openURL(url);
    }
  } catch (error) {
    console.log(error.message);
  }

thanks for the response aryella. i am trying to integrate keycloak login with react native app using inapp-browser. issue is that after opening browser, i can't get any response. only response i get is "type:cancel" when i close the browser. how to close the browser after successful login in inapp-browser. thanks in advance.

jdnichollsc commented 8 months ago

how to close the browser after successful login in inapp-browser.

you need to redirect users to the app using deep linking