2015-11-12 20:35:44 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-11-12 20:35:44 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-11-12 20:35:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
2017-04-12 23:09:48 +00:00
|
|
|
var PropTypes = require('prop-types');
|
2016-04-09 03:36:40 +00:00
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {Linking, StyleSheet, Text, TouchableOpacity, View} = ReactNative;
|
2017-05-06 03:50:47 +00:00
|
|
|
var RNTesterBlock = require('./RNTesterBlock');
|
2015-11-12 20:35:44 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class OpenURLButton extends React.Component {
|
|
|
|
static propTypes = {
|
2017-04-12 23:09:48 +00:00
|
|
|
url: PropTypes.string,
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-11-12 20:35:44 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
handleClick = () => {
|
2016-02-29 11:28:48 +00:00
|
|
|
Linking.canOpenURL(this.props.url).then(supported => {
|
2015-11-12 20:35:44 +00:00
|
|
|
if (supported) {
|
2016-02-29 11:28:48 +00:00
|
|
|
Linking.openURL(this.props.url);
|
2015-11-12 20:35:44 +00:00
|
|
|
} else {
|
2018-05-11 20:32:37 +00:00
|
|
|
console.log("Don't know how to open URI: " + this.props.url);
|
2015-11-12 20:35:44 +00:00
|
|
|
}
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-11-12 20:35:44 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-11-12 20:35:44 +00:00
|
|
|
return (
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableOpacity onPress={this.handleClick}>
|
2015-11-12 20:35:44 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text style={styles.text}>Open {this.props.url}</Text>
|
|
|
|
</View>
|
2016-05-20 20:25:29 +00:00
|
|
|
</TouchableOpacity>
|
2015-11-12 20:35:44 +00:00
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-11-12 20:35:44 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class IntentAndroidExample extends React.Component {
|
|
|
|
static title = 'Linking';
|
|
|
|
static description = 'Shows how to use Linking to open URLs.';
|
2015-11-12 20:35:44 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-11-12 20:35:44 +00:00
|
|
|
return (
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Open external URLs">
|
2015-11-12 20:35:44 +00:00
|
|
|
<OpenURLButton url={'https://www.facebook.com'} />
|
|
|
|
<OpenURLButton url={'http://www.facebook.com'} />
|
|
|
|
<OpenURLButton url={'http://facebook.com'} />
|
2016-02-29 11:28:48 +00:00
|
|
|
<OpenURLButton url={'fb://notifications'} />
|
2015-11-12 20:35:44 +00:00
|
|
|
<OpenURLButton url={'geo:37.484847,-122.148386'} />
|
2016-02-29 11:28:48 +00:00
|
|
|
<OpenURLButton url={'tel:9876543210'} />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-11-12 20:35:44 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-12 20:35:44 +00:00
|
|
|
|
|
|
|
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;
|