我想使用React Native Elements表单来让用户输入密码。我的代码如下:
<FormLabel> Passsword </FormLabel>
<FormInput
onChangeText - {(text) => this.setState({password: text})}
/>
如何使他们输入的文本安全,以便没有人可以看到它是什么。
对于textInput,他们有secureTextEntry
,但我还没有找到类似的react native元素。
我想使用React Native Elements表单来让用户输入密码。我的代码如下:
<FormLabel> Passsword </FormLabel>
<FormInput
onChangeText - {(text) => this.setState({password: text})}
/>
如何使他们输入的文本安全,以便没有人可以看到它是什么。
对于textInput,他们有secureTextEntry
,但我还没有找到类似的react native元素。
React Native Elements Input继承自React Native的所有本地TextInput属 性:
参见:https://react-native-training.github.io/react-native-elements/docs/input.html#props
因此,这将正常工作:
import { Input } from 'react-native-elements'
<Input placeholder="password" secureTextEntry={true} />
使用 TextInput
组件的 secureTextEntry
属性来隐藏密码字段
<TextInput
.....
secureTextEntry={true}
/>
此字段接受 true
值用于隐藏文本和false
值用于显示文本。
React Native Elements FormInput不支持secureTextEntry。只需添加一个TextInput而不是FormInput,如果正确设置样式,它将起到相同的作用并且看起来也一样。
<FormInput
{...props}
style={StyleSheet.flatten([
style,
marginTop={marginTop}
autoCapitalize={autoCapitalize}
autoCorrect={autoCorrect}
secureTextEntry={true}
...
/>
FormInput继承了标准React Native TextInput元素所带的所有本机TextInput属性。我们在项目中使用FormInput并将其作为安全输入(secureTextEntry)的一个属性。您可能想查看:https://react-native-training.github.io/react-native-elements/docs/0.19.1/forms.html
你需要在自定义组件中添加一个属性来保护文本。
<FormLabel> Passsword </FormLabel>
<FormInput
isSecure={true}
onChangeText - {(text) => this.setState({password: text})}
/>
<TextInput
secureTextEntry={this.props.isSecure ? this.props.isSecure : false}
/>
do keyboardType="default" and it will work. It worked for me.
<TextInput
style={[styles.textInput]}
placeholder=""
secureTextEntry={hidePassword}
selectionColor={'#000'}
editable={true}
returnKeyType={'next'}
keyboardType="default"
autoFocus={false}
autoCapitalize={'characters'}
placeholderTextColor="rgb(153,153,153)"
onChangeText={(text) => this.onCurrentPassTextChange(text)}
>{currentPassword}</TextInput>
我曾经遇到过同样的问题,通过在 <Input />
中添加以下内容解决了它:
multiline={false} <------THIS
secureTextEntry={true}
根据React Native文档,secureTextEntry不支持多行输入。因此,React Native Elements默认使用多行输入。将multiline设置为false对我有用。
<TextInput
secureTextEntry={true}
placeholder = "Enter your password"
autoCorrect={false}
style={{ height: 44, width: '92%', marginTop: 20, borderColor: 'gray', borderWidth: 1, paddingLeft: 15, borderRadius: 7}}
/>