2

您好,我正在使用 React Native 的 TextInput,并且有一个眼睛选项可以查看或隐藏密码。当我将 secureTextEntry 设置为 true 并在输入中键入另一个字符时,它会清除所有以前的数据并只键入该字符。

这是我的代码:

<TextInput
 ref={ref => this._password = ref}
 style={[style.greyTextStyle, style.textinputStyle]}
 placeholder={strings.PASSWORD}
 secureTextEntry={this.state.securepass}
 placeholderTextColor={color.GREY_TEXT_COLOR}
 underlineColorAndroid='transparent'
 value={this.state.password}
 onChangeText={(text) => { this.setState({ password: text }) }} />

单击 eye btn 时,我切换安全文本输入

showPassword() {
 this.setState({ securepass: !this.state.securepass });
 if (this.state.securepass == false) {
  this.setState({ passIcon: 'eye' })
 } else {
  this.setState({ passIcon: 'eye-off' })
 }
}

请帮忙。

4

2 回答 2

1

clearTextOnFocus在 textInput 中将属性设置为 false 可能会有所帮助

<TextInput
 clearTextOnFocus={false}
 ref={ref => this._password = ref}
 style={[style.greyTextStyle, style.textinputStyle]}
 placeholder={strings.PASSWORD}
 secureTextEntry={this.state.securepass}
 placeholderTextColor={color.GREY_TEXT_COLOR}
 underlineColorAndroid='transparent'
 value={this.state.password}
 onChangeText={(text) => { this.setState({ password: text }) }} />
于 2018-11-08T08:37:18.347 回答
0

我认为这是 iOS 原生行为。请检查此https://github.com/facebook/react-native/issues/9148和此https://github.com/facebook/react-native/issues/12939。您可以尝试在切换显示/隐藏密码之前保存该值,然后再次设置。

于 2018-11-08T08:31:53.133 回答