Created
May 24, 2018 05:54
-
-
Save zi6xuan/357796652fdb05d41f4eb0228668e5d7 to your computer and use it in GitHub Desktop.
react-native text support url link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
richText(str: string) { | |
// | |
let strAry = new Array(); | |
let startI = 0; | |
let urls = str.match(/<https?\:\/\/.+?>/g); | |
let textAry = str.split(/<https?\:\/\/.+?>/); | |
let viewAry = new Array(); | |
for (let i = 0; i < textAry.length; i++) { | |
let urlCom = null; | |
if (urls != null && i < urls.length) { | |
let url = urls[i].replace("<", "").replace(">", ""); | |
urlCom = ( | |
<Text onPress={(event) => this.onLink(url)} | |
style={{ color: '#0000FF', borderBottomColor: '#0000FF', borderBottomWidth: 1 }}> | |
{url} | |
</Text> | |
); | |
} | |
viewAry.push( | |
<Text key={i}> | |
{textAry[i]} | |
{urlCom} | |
</Text> | |
); | |
} | |
return ( | |
<Text style={[styles.text, styles.textPadding]}> | |
{viewAry} | |
</ Text> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment