Skip to content

Commit 1d75810

Browse files
authored
Merge pull request #49 from Kikketer/master
Update the isAvailable to return a boolean
2 parents 7dd3b6a + 8b2b1fa commit 1d75810

File tree

5 files changed

+49
-48
lines changed

5 files changed

+49
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Thanks goes to these wonderful people:
241241
<!-- CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
242242
| [<img alt="jdnichollsc" src="https://avatars3.githubusercontent.com/u/2154886?v=3" width="100" /><br /><sub><b>Juan Nicholls</b></sub>](https://github.com/jdnichollsc)<br />[✉](mailto:[email protected]) | [<img alt="EQuimper" src="https://avatars3.githubusercontent.com/u/15819498?v=3" width="100" /><br /><sub><b>Emanuel Quimper</b></sub>](https://github.com/EQuimper)<br />[✉](mailto:[email protected]) | [<img alt="bonesyblue" src="https://avatars3.githubusercontent.com/u/7486722?v=3" width="100" /><br /><sub><b>Jonathan Bones</b></sub>](https://github.com/bonesyblue)<br />[✉](mailto:[email protected]) | [<img alt="mlazari" src="https://avatars3.githubusercontent.com/u/4928274?v=3" width="100" /><br /><sub><b>Mihai Lazari</b></sub>](https://github.com/mlazari) | [<img alt="maestor" src="https://avatars3.githubusercontent.com/u/3604902?v=3" width="100" /><br /><sub><b>Kalle Haavisto</b></sub>](https://github.com/maestor)<br />[✉](mailto:[email protected]) | [<img alt="plamworapot" src="https://avatars3.githubusercontent.com/u/4770354?v=3" width="100" /><br /><sub><b>Worapot Pengsuk</b></sub>](https://github.com/plamworapot) | [<img alt="adammcarth" src="https://avatars3.githubusercontent.com/u/3016455?v=3" width="100" /><br /><sub><b>Adam McArthur</b></sub>](https://github.com/adammcarth)<br />[✉](mailto:[email protected]) |
243243
| :---: | :---: |:---: | :---: | :---: | :---: | :---: |
244-
| [<img alt="SnaiNeR" src="https://avatars3.githubusercontent.com/u/39980963?v=3" width="100" /><br /><sub><b>Artem Emelyanov</b></sub>](https://github.com/SnaiNeR)<br />[](mailto:[email protected]) | [<img alt="rbscott" src="https://avatars2.githubusercontent.com/u/882258?v=4&s=117" width="100" /><br /><sub><b>Robert Scott</b></sub>](https://github.com/rbscott) |
244+
| [<img alt="SnaiNeR" src="https://avatars3.githubusercontent.com/u/39980963?v=3" width="100" /><br /><sub><b>Artem Emelyanov</b></sub>](https://github.com/SnaiNeR)<br />[](mailto:[email protected]) | [<img alt="rbscott" src="https://avatars2.githubusercontent.com/u/882258?v=4&s=117" width="100" /><br /><sub><b>Robert Scott</b></sub>](https://github.com/rbscott) | [<img alt="Kikketer" src="https://avatars0.githubusercontent.com/u/958042?s=460&v=4" width="100" /><br /><sub><b>Chris Weed</b></sub>](https://github.com/kikketer) |
245245
<!-- CONTRIBUTORS-LIST:END -->
246246

247247
## Supporting 🍻

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-inappbrowser-reborn",
3-
"version": "1.3.13",
3+
"version": "2.0.0",
44
"description": "InAppBrowser for React Native",
55
"main": "index.js",
66
"readmeFilename": "README.md",
@@ -36,4 +36,4 @@
3636
"babel-core": "^6.26.0",
3737
"flow-bin": "^0.80.0"
3838
}
39-
}
39+
}

0 commit comments

Comments
 (0)