I would like to integrate a small text (my e-mail address) but I would like the user can to copy this text. I thought of a button, when we click on it the e-mail address is copy and can be past outside the app. How to do this?
<View>
<Text style={{color: 'red', fontSize: 14 , fontFamily:'Arial', fontStyle: 'bold', textAlign: 'center', marginTop: 3, marginLeft: 25, marginBottom: 17}}>
[email protected]
</Text></View>
I am novice, any help would be greatly appreciated.
You can use Clipboard from @react-native-community.
Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.
Now when we click on the button 'Copy to Clipboard', the function copyToClipboard gets triggered through onClick event which copies the state value to the clipboard with copy() function. Now we can copy our text anywhere by just clicking Ctrl+V key.
You can use Clipboard
from @react-native-community.
Here's how you can use it:
import Clipboard from '@react-native-community/clipboard';
<TouchableOpacity onPress={() => Clipboard.setString('[email protected]')}>
<View>
<Text style={{color: 'red', fontSize: 14 , fontFamily:'Arial', fontStyle: 'bold', textAlign: 'center', marginTop: 3, marginLeft: 25, marginBottom: 17}}>
[email protected]
</Text>
</View>
</TouchableOpacity>
Set selectable prop of the Text component true and the content will be copied to the clipboard with long press on the text.
<Text selectable={true}>
Your text
</Text>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With