Created
June 9, 2024 01:58
-
-
Save pH-7/134304ebc1340179a81490f669809a62 to your computer and use it in GitHub Desktop.
React Native PhoneLink component. e.g. <PhoneLink phoneNumber="+442011145678" />
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { StyleSheet, Text, TouchableOpacity, Linking } from 'react-native'; | |
interface PhoneLinkProps { | |
phoneNumber: string; | |
} | |
export const PhoneLink: React.FC<PhoneLinkProps> = ({ phoneNumber }) => { | |
const handlePress = () => { | |
Linking.openURL(`tel:${phoneNumber}`); | |
}; | |
return ( | |
<TouchableOpacity style={styles.container} onPress={handlePress}> | |
<Text style={styles.phoneNumber}>{phoneNumber}</Text> | |
</TouchableOpacity> | |
); | |
}; | |
const styles = StyleSheet.create({ | |
container: { | |
backgroundColor: '#007AFF', | |
borderRadius: 8, | |
paddingVertical: 12, | |
paddingHorizontal: 16, | |
alignItems: 'center', | |
}, | |
phoneNumber: { | |
color: '#FFFFFF', | |
fontSize: 18, | |
fontWeight: 'bold', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage,
Enjoy! 🎉 Happy React Native development 🚀