android – React Native |在Text上下文菜单中添加选项

我正在使用版本为0.51的react-native应用程序.

在一个视图中,我想为文本选择上下文菜单添加一个新选项.

我没有在react-native的Text组件中找到任何属性来执行此操作.

经过几个小时的谷歌搜索后,我通过在AndroidManifest.xml中添加以下内容找到了这个Android解决方案

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

这增加了一个新选项,其名称为我的应用程序“Book App”

《android – React Native |在Text上下文菜单中添加选项》
《android – React Native |在Text上下文菜单中添加选项》

但我觉得这不是最好的解决方案,因为:

1-我需要在android平台代码中做出反应,在Android和iOS上表现相同
2-我不知道如何更改选项的名称.
3-单击此选项时,我不知道如何触发特定操作.

在Text组件的上下文菜单中添加新选项的任何其他解决方案?

最佳答案 当我们在我的公司开发这个应用程序并且唯一的解决方案是本地实现它时,我们遇到了同样的问题,我们只是开源的

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>
点赞