![](/img/trans.png)
[英]How can I press a button from within another touchable/pressable? [React Native]
[英]how to create a button, pressable or a touchable opacity that redirects us to a website using react native
大家好,我是 react native 的新手,我想知道如何创建一个按钮、touchableopacity 或 pressable,将我们重定向到使用 react native 的网站
简单地说,有一个来自 React Native 的名为Linking Doc的模块,您可以在其中使用 function openURL
,其中输入参数只是您的网站链接。
完整示例:
从 'react-native' 导入 { Linking, Text, TouchableOpacity }
<TouchableOpacity style={{ width: 100, height: 60, backgroundColor: "red" }} onPress={() => Linking.openURL("https://stackoverflow.com")} > <Text> Go to my website </Text> </TouchableOpacity>
此 function 重定向到设备的默认外部浏览器。 如果你想使用本机 WebView 检查这个库WebView (几个版本之前包含在 react-native 库中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.