首页 > 其他 > 详细

react 实现点击跳转到拨号界面

时间:2019-11-27 13:13:25      阅读:479      评论:0      收藏:0      [点我收藏+]
import React, { Component } from ‘react‘;
import {
    View,
    Text,
    Image,
    StyleSheet,
    TouchableOpacity,
    NativeModules,
    Platform,
    StatusBar,
    ScrollView,
    Alert ,
    Linking
} from "react-native";
import { Toast } from "../../components/base/Toast";
class GrabSheetVc extends Component {
    constructor(props) {
        super(props);
        this.state = {  }
        this.phone = 18888888888
    }
 render() {
        return (
  
<View style={styles.v4}>
                            <TouchableOpacity style={{ borderRadius: 27, overflow: ‘hidden‘, marginTop: 13 }} onPress={this.callMerchant}>
                                <Image
                                    source={require(‘../../../resource/order/telephone.png‘)}
                                    style={{ width: Utils.fontRem * 54, height: Utils.fontRem * 54 }}
                                    resizeMode=‘contain‘
                                />
                            </TouchableOpacity>
                            <Text style={{ fontSize: 14, color: ‘#333‘, marginTop: 9.5 }}>联系雇主</Text>
</View>
)}
}
 /**
   *  拨打电话
   * @param {string} phone 版本号
   * @example
   * call(‘18888888888‘)
   */
  call = phone => {
    const url = `tel:${phone}`;
    Linking.canOpenURL(url)
      .then(supported => {
        if (!supported) {
          return Alert.alert(‘提示‘, `您的设备不支持该功能,请手动拨打 ${phone}`, [
            { text: ‘确定‘ }
          ]);
        }
        return Linking.openURL(url);
      })
      .catch(err => Toast.show(`出错了:${err}`, 1.5));
  };
  callMerchant = (phone) => {
    this.call(this.phone);
  };
技术分享图片

 

 技术分享图片

 

 

react 实现点击跳转到拨号界面

原文:https://www.cnblogs.com/james-L/p/11940262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!