1

I am trying to format links which are present in text input, something like how stack overflow does. On click the link should open in the browser.

Does one have any idea how this can be done in React Native?

Kevin M. Mansour
  • 2,915
  • 6
  • 18
  • 35
Aakash Rathee
  • 523
  • 3
  • 17
  • I don't know if I'm getting the question correctly, but my guess is that React Native Linking would do the trick: https://reactnative.dev/docs/linking – MIPB May 10 '21 at 18:14
  • The link can be anything, as it will be provided by the user not hard coded – Aakash Rathee May 10 '21 at 18:19
  • This might help https://stackoverflow.com/a/55069926/811405 – Can Poyrazoğlu May 10 '21 at 18:25
  • Opening the links isn't the problem, it how will I detect if there is a link in the text provided by the user and the formatting for the rest of the text should not change – Aakash Rathee May 10 '21 at 18:27
  • I see what you mean. I've never done this before, but my guess is that you would let the user write whatever they want inside brackets in your text, and then whatever it is inside them should be transformed into a link by your code. [https....] – MIPB May 10 '21 at 18:30
  • Thats what im trying to do – Aakash Rathee May 10 '21 at 18:53

2 Answers2

0

Found something similar to what I was looking, doesn't change the styling of the text but makes the links in the click able.

https://github.com/AR-Studios-Group/Formated-Text-View

Aakash Rathee
  • 523
  • 3
  • 17
-2
import React, { Component } from 'react';
import { View, StyleSheet, Button, Linking } from 'react-native';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
       <Button title="Click me" onPress={ ()=>{ Linking.openURL('https://google.com')}} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
  },
});
ggorlen
  • 44,755
  • 7
  • 76
  • 106