Skip to content

Commit c3a95da

Browse files
author
Chris Weed
committed
Update the isAvailable to return a boolean
1 parent 17c9ba7 commit c3a95da

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

example/App.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* @flow
77
*/
88

9-
import React, {Component} from 'react'
9+
import React, { Component } from 'react'
1010
import {
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'
2020
import 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: {

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function _waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {
122122

123123
async function isAvailable(): Promise<void> {
124124
if (Platform.OS === 'android') {
125-
return Promise.resolve();
125+
return Promise.resolve(true);
126126
}
127127
else {
128128
return RNInAppBrowser.isAvailable();

ios/RNInAppBrowser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ - (void)_close
181181
// SafariView is available
182182
resolve(@YES);
183183
} else {
184-
reject(@"E_SAFARI_VIEW_UNAVAILABLE", @"SafariView is unavailable", nil);
184+
resolve(@NO);
185185
}
186186
}
187187

0 commit comments

Comments
 (0)