简体   繁体   中英

How to prevent copy to clipboard in TextInput react-native on Android?

I want to prevent user to copy content in TextInput but it works only on iOS but not for Android. How do I can do this in Android?

[Update]: As the link @patel-dhara has given below, I already read commit about contextMenuHidden property and found that only handle onLongClick event on Android. So, still can copy to clipboard on TextInput by double-tap to it.

Here is my code:

<TextInput
  style={styles.input}
  placeholder="Password"
  placeholderTextColor="rgba(255, 255, 255, 0.7)"
  underlineColorAndroid="transparent"
  secureTextEntry={isHidePass}
  returnKeyType="go"
  autoCapitalize="none"
  onChangeText={this.handleTextChange}
  onSubmitEditing={this.handleLogin}
  ref={this.passwordRef}
  contextMenuHidden
  onBlur={() => Clipboard.setString('')}
  onFocus={() => Clipboard.setString('')}
  onSelectionChange={() => Clipboard.setString('')}
/>

you can use contextMenuHidden property of TextInput. It will work on both Platform Android and iOS.

<TextInput contextMenuHidden={true} />

but, It may be supported after react-native version 0.55. for more info link . commit link for that: link

尝试这个:

<TextInput caretHidden={true} selectTextOnFocus={false} />

use this:

<View pointerEvents="none">
  <TextInput ... />
</View>

Checkout pointer events for view: https://facebook.github.io/react-native/docs/view#pointerevents

Another Option: Try clearing the clipboard

<TextInput onFocus={() => Clipboard.setString('')} onSelectionChange={() => Clipboard.setString('')}/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM