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.
I am not able find anything in the react-native official documentation
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.
I am not able find anything in the react-native official documentation
 
    
    You should add 2 attributes
selectTextOnFocus and editable
For example:
<TextInput editable={false} selectTextOnFocus={false} />
 
    
    contextMenuHidden is to disable the user from pasting text into certain fields and to hide context menu.
Update: This hasn’t been included in a release yet. You can always see what release any commit is in by clicking on the link and looking at the tags. so I wouldn't expect it to be on a stable release until 0.55.
<TextInput contextMenuHidden={true} />
Check the commit here: Add option to hide context menu for TextInput
 
    
    Set pointerEvents to none on parent View of TextInput to disable touch events, consider following example:
<View pointerEvents="none">
  <TextInput ... />
</View>
 
    
     
    
    You can use a View and use removeClippedSubviews={true} (works with Android) and use contextMenuHidden={true} (works with IOS)
<View removeClippedSubviews={true}>
  <TextInput contextMenuHidden={true} />
</View>
 
    
    Reference from the following issue https://github.com/facebook/react-native/issues/33697
const App = () => {
  const [selection, setSelection] = useState(null);
  const [text, setText] = useState('');
  return (
    <TextInput 
      selection={selection}
      onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
      value={text}
      onChangeText={(text) => setText(text)}
      style={{ alignSelf: 'center', width: 200, marginTop: 50, backgroundColor: 'grey' }} 
    />
  );
};
 
    
    Below solution works for me for avoiding copy/paste. I am clearing keyboard on onTouchEnd event
const [text1, setText1] = useState('')
    
const clearClipboard = () =>{
 Clipboard.setString('')
}
    
const onChangeText = (text) =>{
 //For android 12+ clipboard autofill option, dont allow text change more than one char..which means user is typing.
 if(text1.length+1 >= text.length){
  setText1(text)
 }
}
    
<TextInput onChangeText={onChangeText} value={text1} contextMenuHidden={true} onTouchEnd={clearClipboard}></TextInput>
 
    
    Use caretHidden={true} if you want to disable all operation like Cut Paste Copy. It will also hide your cursor as well
 
    
    This trick worked for me. Here I am using NativeBase. Keep this <TextInput> inside a <Item> tag.  Now the selection property should not work.
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
 
    
    