react-native Linking

来源:互联网 发布:java aes 256 cbc 编辑:程序博客网 时间:2024/06/18 12:24
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, { Component } from 'react';import {  AppRegistry,  StyleSheet,  Text,  View,  Linking} from 'react-native';class Main extends Component {    clickEvent(){        Linking.canOpenURL(this.props.url).then((data) => {            if(data){                return Linking.openURL(this.props.url);            }else{                alert('error');            }        })    }    render (){        return (            <Text onPress={this.clickEvent.bind(this)}>{'打开'+this.props.url}</Text>        );    }}export default class D20170503 extends Component {  render() {    return (      <View style={styles.container}>          <Main              url={'http://www.dongyi100.com'}              />          <Main              url={'https://www.dongyi100.com'}              />          <Main              url={'tel:1380013800'}              />          <Main              url={'smsto:13800138000'}                />
   <Main              url={'mailto:dongyi100@qq.com'}                />
</View>
); }}const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', },});AppRegistry.registerComponent('D20170503', () => D20170503);

                                             
0 0
原创粉丝点击