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