Javascript 禁用 React-Native 文本输入选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42883864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable Options on React-Native Text Input
提问by firebolt_ash
I am using TextInput for a project and wanted to DISABLE any kind of text selection or actions like (cut/copy/paste/share) as shared in the screenshot below.
我正在为一个项目使用 TextInput,并希望禁用任何类型的文本选择或操作,例如(剪切/复制/粘贴/共享),如下面的屏幕截图所示。
I am not able find anything in the react-native official documentation
我在 react-native 官方文档中找不到任何内容
回答by Artem Tutov
You should add 2 attributes
selectTextOnFocusand editable
您应该添加 2 个属性
selectTextOnFocus和editable
For example:
例如:
<TextInput editable={false} selectTextOnFocus={false} />
回答by Balasubramanian
contextMenuHiddenis to disable the user from pasting text into certain fields and to hide context menu.
contextMenuHidden是禁止用户将文本粘贴到某些字段并隐藏上下文菜单。
Update:This hasn't been included in a release yet. You can always see what release any commit is in by clicking on the linkand looking at the tags. so I wouldn't expect it to be on a stable release until 0.55.
更新:这尚未包含在版本中。您始终可以通过单击链接并查看标签来查看任何提交所在的版本。所以我不希望它在 0.55 之前稳定发布。
<TextInput contextMenuHidden={true} />
Check the commit here: Add option to hide context menu for TextInput
在此处检查提交:添加选项以隐藏 TextInput 的上下文菜单
回答by Shine
Set pointerEventsto none on parent Viewof TextInputto disable touch events, consider following example:
在 parent of上将 pointerEvents设置为 none以禁用触摸事件,请考虑以下示例:ViewTextInput
<View pointerEvents="none">
<TextInput ... />
</View>
回答by funkysoul
Just give your textinput the attribute editable={false}
只需给你的 textinput 属性 editable={false}
回答by linhadiretalipe
You can use a View and use removeClippedSubviews={true} (works with Android) and use contextMenuHidden={true} (works with IOS)
您可以使用 View 并使用 removeClippedSubviews={true} (适用于 Android)并使用 contextMenuHidden={true} (适用于 IOS)
<View removeClippedSubviews={true}>
<TextInput contextMenuHidden={true} />
</View>
<View removeClippedSubviews={true}>
<TextInput contextMenuHidden={true} />
</View>
回答by Anil Chahal
Use caretHidden={true}if you want to disable all operation like Cut Paste Copy. It will also hide your cursor as well
如果要禁用所有操作(如剪切粘贴复制),请使用caretHidden={true}。它也会隐藏您的光标
回答by Pallab Naskar
This trick worked for me. Here I am using NativeBase. Keep this <TextInput>inside a <Item>tag. Now the selection property should not work.
这个技巧对我有用。这里我使用的是 NativeBase。将其保存<TextInput>在<Item>标签中。现在选择属性应该不起作用。
code sample attached below.
下面附上代码示例。
<Item>
<Input
value={this.props.call_state.destination}
onChangeText={text => this.props.setDestination(text)}
returnKeyType={"done"}
keyboardType={"numeric"}
/>
</Item>
You should install nativebase first and then import {Item}from native-base in your component
您应该先安装 nativebase,然后{Item}在组件中从 native-base导入


