Skip to content

Commit

Permalink
Update the isAvailable to return a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Weed committed Mar 1, 2019
1 parent 17c9ba7 commit c3a95da
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
87 changes: 44 additions & 43 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* @flow
*/

import React, {Component} from 'react'
import React, { Component } from 'react'
import {
Platform,
StyleSheet,
Text,
View,
Button,
Alert,
TextInput,
Platform,
StyleSheet,
Text,
View,
Button,
Alert,
TextInput,
StatusBar,
} from 'react-native'
import InAppBrowser from 'react-native-inappbrowser-reborn'
Expand All @@ -37,38 +37,39 @@ export default class App extends Component {
}
sleep = m => new Promise(r => setTimeout(r, m))
async openLink() {
try {
await InAppBrowser.isAvailable()
StatusBar.setBarStyle('light-content')
const response = await InAppBrowser.open(this.state.url, {
// iOS Properties
dismissButtonStyle: 'cancel',
preferredBarTintColor: 'gray',
preferredControlTintColor: 'white',
readerMode: 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_right',
endExit: 'slide_out_left',
},
headers: {
'my-custom-header': 'my custom header value'
},
})
await this.sleep(800)
Alert.alert('Response', JSON.stringify(response))
} catch (error) {
Alert.alert(error.message)
if (await InAppBrowser.isAvailable()) {
try {
StatusBar.setBarStyle('light-content')
const response = await InAppBrowser.open(this.state.url, {
// iOS Properties
dismissButtonStyle: 'cancel',
preferredBarTintColor: 'gray',
preferredControlTintColor: 'white',
readerMode: 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_right',
endExit: 'slide_out_left',
},
headers: {
'my-custom-header': 'my custom header value'
},
})
await this.sleep(800)
Alert.alert('Response', JSON.stringify(response))
} catch (error) {
Alert.alert(error.message)
}
}
}

Expand All @@ -80,7 +81,7 @@ export default class App extends Component {
<Text style={styles.instructions}>Type the url</Text>
<TextInput
style={styles.urlInput}
onChangeText={(text) => this.setState({url: text})}
onChangeText={(text) => this.setState({ url: text })}
value={this.state.url}
/>
<View style={styles.openButton}>
Expand Down Expand Up @@ -111,9 +112,9 @@ const styles = StyleSheet.create({
marginBottom: 5,
},
urlInput: {
height: 40,
height: 40,
width: '100%',
borderColor: 'gray',
borderColor: 'gray',
borderWidth: 1,
},
openButton: {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function _waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {

async function isAvailable(): Promise<void> {
if (Platform.OS === 'android') {
return Promise.resolve();
return Promise.resolve(true);
}
else {
return RNInAppBrowser.isAvailable();
Expand Down
2 changes: 1 addition & 1 deletion ios/RNInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ - (void)_close
// SafariView is available
resolve(@YES);
} else {
reject(@"E_SAFARI_VIEW_UNAVAILABLE", @"SafariView is unavailable", nil);
resolve(@NO);
}
}

Expand Down

0 comments on commit c3a95da

Please sign in to comment.