【发布时间】:2021-10-13 00:26:31
【问题描述】:
我想用 React Native 打电话,我是 React Native 的初学者,所以我遇到了这个看起来像我的问题 => How to make phone call in React Native?
所以,这是我的代码的一部分,但它不起作用,当我点击图标时,什么都没有发生,我的终端上也没有错误,这很奇怪。这是我的代码:
import React from 'react';
import { Image, Text, View, StyleSheet } from 'react-native';
import { Avatar } from "react-native-elements";
import { Linking } from 'react-native';
export const makeCall = () => {
let phoneNumber = '';
if (Platform.OS === 'android') {
phoneNumber = 'tel:${0123456789}';
} else {
phoneNumber = 'telprompt:${0123456789}';
}
Linking.openURL(phoneNumber);
};
const Contacts = () => {
return (
<View style={styles.column}>
<Avatar
size={65}
rounded
overlayContainerStyle={{ backgroundColor: '#fff' }}
icon={{ name: 'phone', color: '#113D78', type: 'font-awesome' }}
onPress={() => makeCall}
style={{
width: 65,
height: 65,
borderRadius: 50,
borderWidth: 2,
borderColor: '#113D78',
}}
/>
<Text style={styles.subtitle}>Phone</Text>
</View>
);
}
导出默认联系人;
【问题讨论】: