我想集成一个小文本(我的邮箱地址),但我希望用户可以复制此文本.我想到了一个按钮,当我们点击它时,邮箱地址是copy,可以在应用程序之外通过.怎么做?

<View>
<Text style={{color: 'red', fontSize: 14 , fontFamily:'Arial', fontStyle: 'bold', textAlign: 'center', marginTop: 3, marginLeft: 25, marginBottom: 17}}> 
             mail@mail.com
</Text></View>

我是新手,任何帮助都将不胜感激.

推荐答案

你可以用Clipboard from @react-native-community.

以下是您如何使用它:

import Clipboard from '@react-native-community/clipboard';

<TouchableOpacity onPress={() => Clipboard.setString('mail@mail.com')}>
  <View>
    <Text style={{color: 'red', fontSize: 14 , fontFamily:'Arial', fontStyle: 'bold', textAlign: 'center', marginTop: 3, marginLeft: 25, marginBottom: 17}}> 
                mail@mail.com
    </Text>
  </View>
</TouchableOpacity>

React-native相关问答推荐

react-native useEffect / useFocusEffect / useCallback 没有正确更新

RTK 查询显示互联网何时关闭?

React Native TextInput 在android上打开时会自动关闭

React Native Child Parent 通信

如何启用 stacktrace react-native run-android 命令?

如何以编程方式在 react-native 中截屏

如何在 React Navigation createStackNavigator 中更改字体系列

如何从 React Native-App 中的 res/drawable-folder 加载图像?

错误:无法解析模块`buffer`

react native图像不适用于特定 URL

如何在 ubuntu 上安装 facebook watchman?

使用带有样式组件的动画

将 React Native 升级到 0.60-RC2 后找不到库libjsc.so

区别需要MainQueueSetup 和dispatch_get_main_queue?

无法解析模块react-navigation

在react-native中调试应用程序崩溃

React-Native 最低 Android API 级别

React Native:如何将文件拆分为多个文件并导入它们?

手动调用 React.PropTypes 验证 React native "^0.30.0"

ReactNative Flatlist - RenderItem not working