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);
相关文章推荐
- 【React Native开发】React Native控件之Image组件讲解与美团首页顶部效果实例(10)
- 【React Native开发】React Native控件之WebView组件详解以及实例使用(22)
- 【React Native开发】React Native控件之ListView组件讲解以及最齐全实例(19)
- 【React Native开发】React Native控件之Image组件讲解与美团首页顶部效果实例(10)
- React-Native TextInput组件详解及实例代码
- 【React Native开发】React Native控件之Image组件解说与美团首页顶部效果实例(10)
- React-Native实现ListView组件之上拉刷新实例(iOS和Android通用)
- React Native View组件实例
- ReactNative学习实例(八) 第三方组件TabNavigator底部导航栏
- 【React Native开发】React Native控件之ListView组件解说以及最齐全实例(19)
- 【React Native开发】React Native控件之DrawerLayoutAndroid抽屉导航切换组件讲解(13)
- ReactNativeiOS(二)读书记录 8动手写组件
- React Native Android 组件IntentAndroid 实现拨打电话
- 【React Native开发】React Native控件之TextInput组件讲解与QQ登录界面实现(11)
- 【React Native开发】React Native For Android环境配置以及第一个实例
- react-native图片组件的使用
- 【React Native开发】React Native控件之Text组件讲解(9)
- React-Native改变FB官网实例
- react native组件学习(三)
- react-native组件学习(二)