Văn Quyết
Văn Quyết

Reputation: 2526

How to select/highlight text in React Native

I am making an English Reading app. When the user clicks on a word, they will see the translation of that word.

So how to make text is selected when the user clicks and holds for some time? I desire something likes document.onselectchange event in JavaScript for the web.

Upvotes: 1

Views: 3210

Answers (1)

ThatCoderGuy
ThatCoderGuy

Reputation: 677

wrap the Text component with one of the available Touchable components i.e TouchableOpacity. You'll then have access to the onLongPress prop, where you can call a function which allows you to change the background color of the text to give the feel of being selected.

Upvotes: 2

Related Questions