Reputation: 10561
Nothing in the docs about this. I want to disable the small popup below when clicking on a TextInput in React Native.
Any ideas ?
Upvotes: 3
Views: 14406
Reputation: 1
If you set pointerEvents="none"
on a View surrounding the TextInput it will prevent the context menu from displaying:
<View removeClippedSubviews pointerEvents="none">
<TextInput contextMenuHidden />
</View>
This will work for iOS, Android, and web
Upvotes: 0
Reputation: 43
I created custom textview Component for this. To disable the full-screen text input UI that appears when a TextInput component receives focus on Android 13. I have used the The disableFullscreenUI prop. This the only solution that I have found so far which works for all the android versions.
//Code
import React, { useState } from 'react';
import { TextInput as RNTextInput, Platform } from 'react-native';
import Clipboard from '@react-native-community/clipboard';
const withClipboardRestriction = Component => {
const WrappedComponent = (props, ref) => {
const [value, setValue] = useState('');
const handleChange = text => {
// Check if the new text is the same as the current text plus one
character
// This means the user has typed a character, not pasted text
if (
text === value + text.slice(-1) ||
text === value.slice(0, -1) ||
text.length <= value.length
) {
setValue(text);
if (props.onChangeText) {
props.onChangeText(text);
}
}
};
const clearClipboard = () => {
Clipboard.setString('');
};
const newProps = {
...props,
onChangeText: handleChange,
autoCorrect: false,
spellCheck: false,
onTouchEnd: clearClipboard,
onFocus: clearClipboard,
undefinedText: '',
...(Platform.OS === 'android' && Platform.Version >= 33
? { disableFullscreenUI: true }
: {}),
};
return <Component {...newProps} ref={ref} contextMenuHidden={true} />;
};
return React.forwardRef(WrappedComponent);
};
export const TextInput = withClipboardRestriction(RNTextInput);
Upvotes: 0
Reputation: 832
Below solution works for me. 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>
Upvotes: 0
Reputation: 24
for stop copy paste the following code is
<TextInput contextMenuHidden={true}/>
Upvotes: 2
Reputation: 39
for ios
<TextInput contextMenuHidden={true}
for Android
<View removeClippedSubviews={true}>
<TextInput contextMenuHidden={true} />
</View>
Surender Kumar's answer: React Native 55.4: contextMenuHidden does not hide menu on Android - Disable Options on React-Native Text Input
Upvotes: 3
Reputation: 2065
<TextInput
contextMenuHidden={true}
value={this.state.text}
onChangeText={(text) => this.setState({ text})}
/>
Upvotes: 10