React Native学习

React Native 点击软键盘消失按钮后,点击按钮需要点击

2017-09-11  本文已影响100人  雨飞飞雨

经过试验发现点击软键盘消失按钮后,或者点击屏幕其他的地方,软键盘消失,点击按钮却需要两次的原因是,焦点还在原来的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();
}

参考文章:
键盘遮挡问题处理;
ReactNative之键盘Keyboard的弹出与消失示例;

上一篇下一篇

猜你喜欢

热点阅读