2015-11-12 20:35:44 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule LinkingExample
|
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');
|
2015-11-12 20:35:44 +00:00
|
|
|
var {
|
2016-02-29 11:28:48 +00:00
|
|
|
Linking,
|
2015-11-12 20:35:44 +00:00
|
|
|
StyleSheet,
|
|
|
|
Text,
|
2016-05-20 20:25:29 +00:00
|
|
|
TouchableOpacity,
|
2015-11-12 20:35:44 +00:00
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = 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 {
|
|
|
|
console.log('Don\'t know how to open URI: ' + this.props.url);
|
|
|
|
}
|
|
|
|
});
|
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 (
|
2016-05-20 20:25:29 +00:00
|
|
|
<TouchableOpacity
|
2015-11-12 20:35:44 +00:00
|
|
|
onPress={this.handleClick}>
|
|
|
|
<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;
|