这个问题与此非常相似,但是,由于某些原因,除了回车键(Enter键(之外,每个键都可以工作。如果密码正确,我想让用户进入下一页。如有任何帮助,将不胜感激
//代码
<TextInput
style={styles.txtfield}
placeholder="Password"
placeholderTextColor = 'rgba(249, 129, 37, 1)'
secureTextEntry={true}
onChangeText={ password => this.setState({ password })}
keyboardType="default"
returnKeyType="next"
onKeyPress={ (event) => {
if(event.nativeEvent.key == "Enter"){
alert(event.nativeEvent.key) // doesn't output anything nor execute the signin function
// this.signIn();
}
else {
alert('Something else Pressed') // show a valid alert with the key info
}
}}
/>
只有当存在multiline
TextInput
时,才会为Enter键获得onPress
事件。
对于单行TextInput
,您将在onSubmitEditing
方法中获得"Enter"或"Submit"按键事件。
<TextInput
style={styles.txtfield}
placeholder="Password"
placeholderTextColor = 'rgba(249, 129, 37, 1)'
secureTextEntry={true}
onChangeText={ password => this.setState({ password })}
keyboardType="default"
returnKeyType="next"
onSubmitEditing={()=>{
alert('on submit') // called only when multiline is false
}}
onKeyPress={ (event) => {
if(event.nativeEvent.key == "Enter"){
alert(event.nativeEvent.key) //called when multiline is true
// this.signIn();
}
else {
alert('Something else Pressed')
}
}}
/>