Reputation: 4319
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"
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?
Upvotes: 9
Views: 2430
Reputation: 171
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>
Upvotes: 4