react-native(리액트 네이티브) API - Linking
const React = require('react')
const PropTypes = require('prop-types')
const ReactNative = require('react-native')
const {
Linking, StyleSheet, Text, TouchableOpacity, View,
} = ReactNative
class OpenURLButton extends React.Component {
static propTypes = {
url: PropTypes.string,
}
handleClick = () => {
Linking.canOpenURL(this.props.url).then(supported => {
if (supported) {
Linking.openURL(this.props.url)
} else {
console.log(`Don't know how to open URI: ${this.props.url}`)
}
})
}
render() {
return (
<TouchableOpacity onPress={this.handleClick}>
<View style={styles.button}>
<Text style={styles.text}>Open {this.props.url}</Text>
</View>
</TouchableOpacity>
)
}
}
export default class IntentAndroidExample extends React.Component {
render() {
return(
<View style={styles.container}>
<OpenURLButton url="https://www.facebook.com" />
<OpenURLButton url="http://www.facebook.com" />
<OpenURLButton url="https://facebook.com" />
<OpenURLButton url="fb//notifications" />
<OpenURLButton url="geo:37.484847,-122.148386" />
<OpenURLButton url="tel:9876543210" />
</View>
)
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
padding: 10,
paddingTop: 30,
},
button: {
padding: 10,
backgroundColor: '#3B5998',
marginBottom: 10,
},
text: {
color: 'white',
},
})
module.exports = IntentAndroidExample
'프로그래밍(Programming) > 리액트 네이티브(React Native)' 카테고리의 다른 글
react-native(리액트 네이티브) API - PanResponder (0) | 2019.01.07 |
---|---|
react-native(리액트 네이티브) API - OrientationChange (0) | 2019.01.07 |
react-native(리액트 네이티브) API - LayoutFlexbox (0) | 2019.01.07 |
react-native(리액트 네이티브) API - LayoutEvent (0) | 2019.01.07 |
react-native(리액트 네이티브) API - LayoutAnimation (0) | 2019.01.07 |