反应原生内联文本链接

Ste*_*rey 2 react-native

我需要将Text组件中的选择文本链接到指向外部URL.我已经包含了一个TouchableOpacity并根据需要指定了宽度和高度,但是TouchableOpacity现在似乎与相邻文本重叠.例:

<Text>Lorem ipsum dolor sit amet, <TouchableOpacity onPress={() => {Linking.openURL('http://www.example.com/')}} style={{width: 108, height: 11}}><Text>consectetur adipiscing</Text></TouchableOpacity> elit. Fusce congue malesuada euismod.</Text>

TouchableOpacityText组件内部保持内联的最佳方法是什么?

Hen*_*k R 14

这样怎么样?

import { Text, Linking } from 'react-native';

<Text>Hey guys I wanted to share this awesome thing just press
  <Text
    style={{color: 'red'}}
    onPress={() => {Linking.openURL('http://www.example.com/')}}
  >
    here
  </Text>
  to see it in your browser
</Text>
Run Code Online (Sandbox Code Playgroud)

  • 如何使用可触摸的不透明度进行内联链接? (3认同)
  • 抱歉,但 onPress 方法不适用于 Text 节点,尽管文档强调它确实如此。无法到达任何地方 (2认同)