如果用户在react Native中滑动电话图标,我尝试拨打电话号码。例如,如果我的手机上有(999)-996-5432,则当用户滑动图标时,应自动拨打此号码。下面是我的handleclick代码
export default class ServiceListDetails extends Component {
handleClick = (link) => {
Linking.canOpenURL(link).then(suppported => {
if (supported) {
Linking.openURL(link);
} else {
console.log('Don\'t know how to open URI: ' + link);
}
});
};
下面是我调用handleClick的代码:
return(
<Text style={styles.Address1}>{item.addr} </Text>
<View style={styles.phoneImg}>
<TouchableOpacity
onPress={() => { this.handleClick('tel:${item.phone}')}}>
<Image source={require('../images/Phone.png')} style={styles.actionImage}/>
</TouchableOpacity>
<Text style={styles.Address1}>{item.phone}</Text>
</View>
)
item.phone来自我的JSON文件。下面是我的JSON文件:
[
{
"id":"2",
"fk": 1,
"addr": "123 test drive, Ring road test",
"phone": "(999)-345-7896"
},
{
"id":"3",
"fk": 1,
"addr": "123 test drive, Test Road",
"phone": "(951)-765-2222"
}
]