/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local */ import React, {Component} from 'react'; import { Platform, StyleSheet, Text, View, Button, Alert, TextInput, StatusBar, Linking, } from 'react-native'; import InAppBrowser from 'react-native-inappbrowser-reborn'; const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', }); export default class App extends Component { constructor(props) { super(props); this.state = { url: 'https://www.google.com', statusBarStyle: 'dark-content', }; } sleep(timeout) { return new Promise((resolve) => setTimeout(resolve, timeout)); } async openLink() { const {url, statusBarStyle} = this.state; try { if (await InAppBrowser.isAvailable()) { // A delay to change the StatusBar when the browser is opened const animated = true; const delay = animated && Platform.OS === 'ios' ? 400 : 0; setTimeout(() => StatusBar.setBarStyle('light-content'), delay); const result = await InAppBrowser.open(url, { // iOS Properties dismissButtonStyle: 'cancel', preferredBarTintColor: '#453AA4', preferredControlTintColor: 'white', readerMode: false, animated, modalPresentationStyle: 'fullScreen', modalTransitionStyle: 'partialCurl', modalEnabled: true, enableBarCollapsing: false, // Android Properties showTitle: true, toolbarColor: '#6200EE', secondaryToolbarColor: 'black', enableUrlBarHiding: true, enableDefaultShare: true, forceCloseOnRedirection: false, // Specify full animation resource identifier(package:anim/name) // or only resource name(in case of animation bundled with app). animations: { startEnter: 'slide_in_right', startExit: 'slide_out_left', endEnter: 'slide_in_left', endExit: 'slide_out_right', }, headers: { 'my-custom-header': 'my custom header value', }, }); // A delay to show an alert when the browser is closed await this.sleep(800); Alert.alert('Response', JSON.stringify(result)); } else { Linking.openURL(url); } } catch (error) { Alert.alert(error.message); } finally { // Restore the previous StatusBar of the App StatusBar.setBarStyle(statusBarStyle); } } getDeepLink(path = '') { const scheme = 'my-demo'; const prefix = Platform.OS === 'android' ? `${scheme}://demo/` : `${scheme}://`; return prefix + path; } async tryDeepLinking() { const loginUrl = 'https://proyecto26.github.io/react-native-inappbrowser/'; const redirectUrl = this.getDeepLink(); const url = `${loginUrl}?redirect_url=${encodeURIComponent(redirectUrl)}`; try { if (await InAppBrowser.isAvailable()) { const result = await InAppBrowser.openAuth(url, redirectUrl, { // iOS Properties ephemeralWebSession: false, // Android Properties showTitle: false, enableUrlBarHiding: true, enableDefaultShare: false, }); Alert.alert('Response', JSON.stringify(result)); } else { Alert.alert('InAppBrowser is not supported :/'); } } catch (error) { Alert.alert('Something’s wrong with the app :('); } } render() { const {statusBarStyle} = this.state; return ( {'Welcome InAppBrowser\nfor React Native!'} Type the url this.setState({url: text})} value={this.state.url} />