react 實現點擊跳轉到撥號界面


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);
  };

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM