How does one Display a Hyperlink in React Native App?

前端 未结 11 1191
孤街浪徒
孤街浪徒 2020-12-12 16:38

How do I display a hyperlink in a React Native app?

e.g.

Google 
相关标签:
11条回答
  • 2020-12-12 17:23

    You can use linking property <Text style={{color: 'skyblue'}} onPress={() => Linking.openURL('http://yahoo.com')}> Yahoo

    0 讨论(0)
  • 2020-12-12 17:26

    To do this, I would strongly consider wrapping a Text component in a TouchableOpacity. When a TouchableOpacity is touched, it fades (becomes less opaque). This gives the user immediate feedback when touching the text and provides for an improved user experience.

    You can use the onPress property on the TouchableOpacity to make the link happen:

    <TouchableOpacity onPress={() => Linking.openURL('http://google.com')}>
      <Text style={{color: 'blue'}}>
        Google
      </Text>
    </TouchableOpacity>
    
    0 讨论(0)
  • 2020-12-12 17:34

    Import Linking the module from React Native

    import { TouchableOpacity, Linking } from "react-native";
    

    Try it:-

    <TouchableOpacity onPress={() => Linking.openURL('http://Facebook.com')}>
         <Text> Facebook </Text>     
    </TouchableOpacity>
    
    0 讨论(0)
  • 2020-12-12 17:35

    Another helpful note to add to the above responses is to add some flexbox styling. This will keep the text on one line and will make sure the text doesn't overlap the screen.

     <View style={{ display: "flex", flexDirection: "row", flex: 1, flexWrap: 'wrap', margin: 10 }}>
      <Text>Add your </Text>
      <TouchableOpacity>
        <Text style={{ color: 'blue' }} onpress={() => Linking.openURL('https://www.google.com')} >
             link
        </Text>
       </TouchableOpacity>
       <Text>here.
       </Text>
     </View>
    
    0 讨论(0)
  • 2020-12-12 17:39

    If you want to do links and other types of rich text, a more comprehensive solution is to use React Native HTMLView.

    0 讨论(0)
提交回复
热议问题