反应本机| 在文本上下文菜单中添加选项

Pet*_*son 5 android react-native

我正在使用版本0.51的React-native应用程序。在一个视图中,我想向文本选择上下文菜单添加一个新选项。

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

经过数小时的谷歌搜索后,我通过在 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>
Run Code Online (Sandbox Code Playgroud)

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

在此处输入图片说明 在此处输入图片说明

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

1-我需要使用非Android平台代码中的react来做到这一点,以使其在android和iOS上具有相同的功能
2-我不知道如何更改选项的名称。
3-我不知道如何在单击此选项时触发特定操作。

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

小智 4

当我们在我的公司开发这个应用程序时,我们遇到了同样的问题,唯一的解决方案是本地实现它,我们刚刚将其开源 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>
Run Code Online (Sandbox Code Playgroud)

  • React Native 对上下文菜单有什么改进吗?顺便说一句,您停止开发可选文本组件了吗?有趣的是,React Native 没有针对这个问题的内置解决方案。我想将图标添加到上下文菜单中,您有为此开发的解决方案吗?真挚地 (4认同)