66 * @flow
77 */
88
9- import React , { Component } from 'react'
9+ import React , { Component } from 'react'
1010import {
11- Platform ,
12- StyleSheet ,
13- Text ,
14- View ,
15- Button ,
16- Alert ,
17- TextInput ,
11+ Platform ,
12+ StyleSheet ,
13+ Text ,
14+ View ,
15+ Button ,
16+ Alert ,
17+ TextInput ,
1818 StatusBar ,
1919} from 'react-native'
2020import InAppBrowser from 'react-native-inappbrowser-reborn'
@@ -37,38 +37,39 @@ export default class App extends Component {
3737 }
3838 sleep = m => new Promise ( r => setTimeout ( r , m ) )
3939 async openLink ( ) {
40- try {
41- await InAppBrowser . isAvailable ( )
42- StatusBar . setBarStyle ( 'light-content' )
43- const response = await InAppBrowser . open ( this . state . url , {
44- // iOS Properties
45- dismissButtonStyle : 'cancel' ,
46- preferredBarTintColor : 'gray' ,
47- preferredControlTintColor : 'white' ,
48- readerMode : false ,
49- // Android Properties
50- showTitle : true ,
51- toolbarColor : '#6200EE' ,
52- secondaryToolbarColor : 'black' ,
53- enableUrlBarHiding : true ,
54- enableDefaultShare : true ,
55- forceCloseOnRedirection : false ,
56- // Specify full animation resource identifier(package:anim/name)
57- // or only resource name(in case of animation bundled with app).
58- animations : {
59- startEnter : 'slide_in_right' ,
60- startExit : 'slide_out_left' ,
61- endEnter : 'slide_in_right' ,
62- endExit : 'slide_out_left' ,
63- } ,
64- headers : {
65- 'my-custom-header' : 'my custom header value'
66- } ,
67- } )
68- await this . sleep ( 800 )
69- Alert . alert ( 'Response' , JSON . stringify ( response ) )
70- } catch ( error ) {
71- Alert . alert ( error . message )
40+ if ( await InAppBrowser . isAvailable ( ) ) {
41+ try {
42+ StatusBar . setBarStyle ( 'light-content' )
43+ const response = await InAppBrowser . open ( this . state . url , {
44+ // iOS Properties
45+ dismissButtonStyle : 'cancel' ,
46+ preferredBarTintColor : 'gray' ,
47+ preferredControlTintColor : 'white' ,
48+ readerMode : false ,
49+ // Android Properties
50+ showTitle : true ,
51+ toolbarColor : '#6200EE' ,
52+ secondaryToolbarColor : 'black' ,
53+ enableUrlBarHiding : true ,
54+ enableDefaultShare : true ,
55+ forceCloseOnRedirection : false ,
56+ // Specify full animation resource identifier(package:anim/name)
57+ // or only resource name(in case of animation bundled with app).
58+ animations : {
59+ startEnter : 'slide_in_right' ,
60+ startExit : 'slide_out_left' ,
61+ endEnter : 'slide_in_right' ,
62+ endExit : 'slide_out_left' ,
63+ } ,
64+ headers : {
65+ 'my-custom-header' : 'my custom header value'
66+ } ,
67+ } )
68+ await this . sleep ( 800 )
69+ Alert . alert ( 'Response' , JSON . stringify ( response ) )
70+ } catch ( error ) {
71+ Alert . alert ( error . message )
72+ }
7273 }
7374 }
7475
@@ -80,7 +81,7 @@ export default class App extends Component {
8081 < Text style = { styles . instructions } > Type the url</ Text >
8182 < TextInput
8283 style = { styles . urlInput }
83- onChangeText = { ( text ) => this . setState ( { url : text } ) }
84+ onChangeText = { ( text ) => this . setState ( { url : text } ) }
8485 value = { this . state . url }
8586 />
8687 < View style = { styles . openButton } >
@@ -111,9 +112,9 @@ const styles = StyleSheet.create({
111112 marginBottom : 5 ,
112113 } ,
113114 urlInput : {
114- height : 40 ,
115+ height : 40 ,
115116 width : '100%' ,
116- borderColor : 'gray' ,
117+ borderColor : 'gray' ,
117118 borderWidth : 1 ,
118119 } ,
119120 openButton : {
0 commit comments