9

I am working on a react-native app with version 0.51. in one view I want to add a new option to text selection context-menu.

I didn't find any property in the Text component of react-native to do this.

after many hours of googling I found this solution for android by adding the following in AndroidManifest.xml

<intent-filter>
    <action android:name="android.intent.action.PROCESS_TEXT" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>

this added a new option with name of my application "Book App"

enter image description here enter image description here

but I don't feel it the best solution because :

1- I need to do it with react not in the android platform code to behave the same on android and iOS
2- I don't know how to change the name of the option.
3- I don't know how to trigger specific action when click this option.

any other solution for adding new option in the context-menu of the Text component?

Peter Wilson
  • 4,150
  • 3
  • 35
  • 62

1 Answers1

4

We had the same problem when this app we were developing at my company and the only solution was to implement it natively, we've just open-sourced it https://github.com/Astrocoders/react-native-selectable-text

import { SelectableText } from 'react-native-selectable-text';

// Use normally, it is a drop-in replacement for react-native/Text
<SelectableText
  menuItems={['Foo', 'Bar']}
  /* Called when the user taps in a item of the selection menu, eventType is the label and content the selected text portion */
  onSelection={({ eventType, content }) => {}}
  /* iOS only (RGB) */
  highlightColor={[255, 0, 0]}
>
  I crave star damage
</SelectableText>
fakenickels
  • 171
  • 6
  • 4
    is there any improvement in React Native about that context menu? Btw, did you stop developing Selectable Text component? It is really so interesting that react native has not builtin solution for this problem. I want to add icon to the context menu, is there any solution you developed for that? Sincerely – Omer Faruk KAYA Jul 25 '21 at 09:04