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

时间:2018-02-20 10:44:16

标签: android react-native

我正在使用版本为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>

这增加了一个新选项,其名称为我的应用程序&#34; Book App&#34;

enter image description here enter image description here

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

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

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

1 个答案:

答案 0 :(得分:1)

在我公司开发此应用程序时,我们遇到了同样的问题,唯一的解决方案是在本地实施,我们只是将其开源 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>
相关问题