How to copy text to clipboard in react-native using text view?

135 views Asked by At

I'm facing the issue with copying the text from TextView in react-native, When long press on TextView the selection view is not appears in iOS.

I've found the some solution using the stack to use <TextInput/> but using this solution it's not working in android platform.

I've 3 TextView in same screen and I want to selected the custom text range from all text view and copy the selected content. Community please guide me on this situation.

1

There are 1 answers

0
Dustin Forsyth On

You should just be able to use the react native 'Text' component. It requires setting the selectable prop on that component to true. Example:

import { Text } from 'react-native'

const TextCopyableComponent = () => {
  return (
    <Text selectable={true}>Selectable Text</Text>
    );
}

Here is the link to the docs on this https://reactnative.dev/docs/text#selectable