[英]KeyboardAvoidingView not working with TextInput password fields Properly on Android
I am using react-native-paper
for Text Input
and using KeyboardAvoidingView
to remove keyboard issues
and put Input
fields above the KeyBoard
, And this is working for other TextInput
fields as expected not with the password fields, But When I remove secureTextEntry={true}
this works fine on android, but this is not the solution as this line is mandatory in Password fields.我正在使用
react-native-paper
进行Text Input
并使用KeyboardAvoidingView
来消除keyboard issues
并将Input
字段放在KeyBoard
上方,这对其他TextInput
字段有效,而不适用于密码字段,但是当我删除secureTextEntry={true}
这适用于Android精品,但由于此行是在密码字段强制性这样是解决不了问题。 I also tried many libraries likereact-native-keyboard-aware-scroll-view我也尝试过很多库,比如react-native-keyboard-aware-scroll-view
/* @flow */
import * as React from 'react';
import {
StyleSheet,
ScrollView,
KeyboardAvoidingView,
} from 'react-native';
import { TextInput, Button} from 'react-native-paper';
export default class App extends React.Component {
static title = 'TextInput';
state = {
name: '',
lastName:'',
phone:'',
email:'',
states:'',
password:'',
repeatPassword:'',
};
render() {
return (
<KeyboardAvoidingView
style={styles.wrapper}
behavior="padding"
keyboardVerticalOffset={80}
>
<ScrollView
style={[styles.container, { backgroundColor: '#bdda' }]}
keyboardShouldPersistTaps={'always'}
removeClippedSubviews={false}
>
<TextInput
style={styles.inputContainerStyle}
label="First Name"
placeholder="Type First Name"
value={this.state.name}
onChangeText={name => this.setState({ name })}
returnKeyType={"next"}
onSubmitEditing={() => { this.lastName.focus() }}
blurOnSubmit={false}
/>
<TextInput
style={styles.inputContainerStyle}
label="Last Name"
placeholder="Type Last Name"
value={this.state.lastName}
onChangeText={lastName => this.setState({ lastName })}
ref={(input) => { this.lastName = input; }}
onSubmitEditing={() => { this.phone.focus() }}
returnKeyType={"next"}
blurOnSubmit={false}
/>
<TextInput
style={styles.inputContainerStyle}
label="Phone"
placeholder="Type Phone"
value={this.state.phone}
onChangeText={phone => this.setState({ phone })}
ref={(input) => { this.phone = input; }}
onSubmitEditing={() => { this.email.focus() }}
returnKeyType={"next"}
blurOnSubmit={false}
/>
<TextInput
style={styles.inputContainerStyle}
label="Email"
placeholder="Type Email"
value={this.state.email}
onChangeText={email => this.setState({ email })}
ref={(input) => { this.email = input; }}
onSubmitEditing={() => { this.states.focus() }}
returnKeyType={"next"}
blurOnSubmit={false}
/>
<TextInput
style={styles.inputContainerStyle}
label="State"
placeholder="Type State"
value={this.state.states}
onChangeText={states => this.setState({ states })}
ref={(input) => { this.states = input; }}
onSubmitEditing={() => { this.password.focus() }}
returnKeyType={"next"}
blurOnSubmit={false}
/>
<TextInput
style={styles.inputContainerStyle}
label="Password"
placeholder="Type Password"
secureTextEntry={true}
value={this.state.password}
onChangeText={password => this.setState({ password })}
ref={(input) => { this.password = input; }}
onSubmitEditing={() => { this.repeatPassword.focus() }}
returnKeyType={"next"}
blurOnSubmit={false}
/>
<TextInput
style={styles.inputContainerStyle}
label="Repeat Password"
placeholder="Type Repeat Password"
secureTextEntry={true}
value={this.state.repeatPassword}
onChangeText={repeatPassword => this.setState({ repeatPassword })}
ref={(input) => { this.repeatPassword = input; }}
returnKeyType={"done"}
blurOnSubmit={true}
/>
<Button onPress={() => alert('I am pressed :P-')} style={{marginTop:20}}>
Submit
</Button>
</ScrollView>
</KeyboardAvoidingView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 25,
marginTop:40,
},
wrapper: {
flex: 1,
},
inputContainerStyle: {
margin: 8,
},
});
To check this issue I also created Demo Project , This issue is only in Android, In belowed Screen Shot Password text fields
is active, but password fields is hidden,为了检查这个问题,我还创建了Demo Project ,这个问题仅在 Android 中,在下面的屏幕截图
Password text fields
是活动的,但密码字段是隐藏的, .
.
Had the same problem.有同样的问题。 I managed it by setting secureTextEntry prop to true only when the password input is focused.
我通过仅在密码输入为焦点时将 secureTextEntry prop 设置为 true 来管理它。
const [secureTextEntry, setSecureTextEntry] = useState(false)
...
<TextInput
style={styles.inputContainerStyle}
label="Repeat Password"
placeholder="Type Repeat Password"
secureTextEntry={secureTextEntry}
value={this.state.repeatPassword}
onFocus={() => setSecureTextEntry(true)}
onChangeText={repeatPassword => this.setState({ repeatPassword })}
ref={(input) => { this.repeatPassword = input; }}
returnKeyType={"done"}
blurOnSubmit={true}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.