您的位置:首页 > Web前端 > React

React-native 中Linking组件的实例

2016-11-07 17:42 387 查看
import React from 'react';
import ReactNative, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
Linking,
TouchableHighlight,
} from 'react-native';
const CustomButton =React.createClass ({

propTypes:{
url:React.PropTypes.string,
},

render(){
return (
<TouchableHighlight
style={styles.LinkingButton}
underlayColor="#a5a5a5"
onPress={() => Linking.canOpenURL(this.props.url).then(supported => {
if(supported){
Linking.openURL(this.props.url);
}else{
console.log('无法打开该URL:'+this.props.url);
}
})} >
<Text style={styles.buttonText}>{this.props.text}</Text>
</TouchableHighlight>
)
}
})

const ToggleAnimatingActivityIndicator = React.createClass({
componentDidMount() {
//Linking 相关内容的处理
var url = Linking.getInitialURL().then((url)=>{
if(url){
console.log('捕捉的URL地址为:'+url)
}
}).catch((error)=>{console.log('错误信息为:',error)})
},
render() {
return(
<View>
<CustomButton url={'http://www.lcode.org'} text="点击打开http网页"/>
<CustomButton url={'https://www.baidu.com'} text="点击打开https网页"/>
<CustomButton url={'smsto:15801060000'} text="点击这里发送短信"/>
<CustomButton url={'tel:15801060000'} text="点击进行打电话"/>
<CustomButton url={'mailto:376690000@qq.com'} text="点击进行发邮件"/>

</View>
)
}
})

var styles = StyleSheet.create({
demo: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
},
text: {
fontSize: 30
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
LinkingButton:{
margin:5,
backgroundColor:'white',
padding:15,
borderBottomWidth:StyleSheet.hairlineWidth,
borderBottomColor:'#cdcdcd'
}
});
AppRegistry.registerComponent('AwesomeProject',() => ToggleAnimatingActivityIndicator);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linking