I'm new to Android and trying to implement a rich editor using Text component of React Native. However when I touch the text and hold for a moment, the text was not highlighted and the top bar with selection actions was not shown like what behaves in a webview or other applications. What am I missing or do I need to implement this feature by myself? If so could you point a direction?
TouchableOpacity can be used to provide feedback by reducing the opacity of the button, allowing the background to be seen through while the user is pressing down. If you need to handle a tap gesture but you don't want any feedback to be displayed, use TouchableWithoutFeedback.
In react native we can make the Text component text Copyable using selectable={true} prop. This prop allows the Text to selectable by user.
You will have to wrap your View inside TouchableHighlight or Opacity etc. I figured out a different way to solve my problem using pointerEvents={'box-none'} on my container View and wrapped the image in a View and gave it pointerEvents={'none'}.
If you want click-and-hold-to-select-text using a Text component, this feature does not currently exist in React Native for iOS. You probably want to upvote https://react-native.canny.io/feature-requests/p/support-selecting-text-within-text-elements-for-copypaste-etc to suggest Facebook add support for this.
However, I've submitted support for on Android, as of React 0.30. But React iOS is drawing characters directly to the screen (and not using the native UITextView that supports a selectable property), so it is not supported there, and likely won't be for a long time.
RN 0.39 adds support to copy the entire text field, but does not yet include support for selecting a subset of the text field for copying.
As of now it is supported by react-native
as well by adding props
selectable={true}
. Also on Android you can change the selected text color with selectionColor='orange'
.
Example:
<Text selectable={true} selectionColor='orange'>You can select me</Text>
Be careful if the text is nested you should add selectable
attribute to the top `
<Text selectable>
<Text>
some selectable text
</Text>
</Text>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With