React Native - 在 iOS 键盘上禁用密码自动填充选项 [英] React Native - Disable Password AutoFill Option on iOS Keyboard

查看:220
本文介绍了React Native - 在 iOS 键盘上禁用密码自动填充选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 React Native 中,如何禁用或阻止键盘显示密码自动填充附件视图选项?TextInput 似乎没有处理禁用此选项的属性.React Native TextInput 文档.我也在 React Native 之上使用 Expo.

In React Native, how do you disable or prevent the keyboard from displaying the Password Autofill accessory view option? There doesn't seem to be an property for TextInput that handles disabling this option. React Native TextInput Documentation. I am also using Expo on top of React Native.

iOS 11 中引入了密码自动填充

密码自动填充附件视图选项的图像

这是一篇关于禁用密码自动填充附件的解决方案的帖子,但我们如何使用 React Native 实现这一点?

Here is a post that has a solution for disabling the password autofill accessory, but how can we achieve this using React Native?

iOS 11 禁用密码自动填充配件视图选项?

推荐答案

来自 RN 文档:

对于 iOS 11+,您可以将 textContentType 设置为用户名或密码,以启用从设备钥匙串自动填充登录详细信息.

For iOS 11+ you can set textContentType to username or password to enable autofill of login details from the device keychain.

这意味着将 textContentType 设置为不同于用户名或密码的内容应禁用 iOS 键盘上的自动填充.但我注意到,即使 textContentType 不是用户名或密码,在 TextInput 组件中将 secureTextEntry 属性设置为 true 也会启用自动填充.这是真的,除了一种特殊情况,当 textContentType 设置为 "oneTimeCode" 时.即使 secureTextEntry 为真,这也会禁用自动填充.

This means that setting textContentType to something different than username or password should disable autofill on iOS keyboard. But I noticed that setting secureTextEntry prop to true in the TextInput component also enables autofill even if textContentType is not username or password. This is true except for one particular case, when textContentType is set to "oneTimeCode". This disables autofill even if secureTextEntry is true.

当我想隐藏密码自动填充并仍将 secureTextEntry 设置为 true 时,我只需要这样做:

When I want to hide the password autofill and still set secureTextEntry to true, I just do this:

<TextInput
  secureTextEntry
  textContentType="oneTimeCode"
/>

还有一些其他随机"情况,其中 textContentType 未设置为用户名或密码,并且 secureTextEntry 为 false,但仍显示自动填充(此处为绝望表情符号).将 textContentType 设置为 "oneTimeCode" 也可以解决此问题:

There are some other "random" cases where textContentType is not set to username or password and secureTextEntry is false but autofill is still shown (despair emoji here). Setting textContentType to "oneTimeCode" also fixes this issue:

<TextInput
  textContentType="oneTimeCode"
/>

这看起来更像是一个黑客而不是解决方案,但它对我有用.

This seems more like a hack than a solution, but it works for me.

这篇关于React Native - 在 iOS 键盘上禁用密码自动填充选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆