经过试验发现点击软键盘消失按钮后,或者点击屏幕其他的地方,软键盘消失,点击按钮却需要两次的原因是,焦点还在原来的TextInput上面。
解决的办法就是,监听软键盘的消失方法,然后在消失方法里面,再一次调用软键盘消失方法:
import { Keyboard, TextInput } from 'react-native';
componentWillMount () {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
}
componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
_keyboardDidShow () {
}
_keyboardDidHide () {
dismissKeyboard();
}
网友评论