經(jīng)過試驗發(fā)現(xiàn)點擊軟鍵盤消失按鈕后咳秉,或者點擊屏幕其他的地方,軟鍵盤消失增蹭,點擊按鈕卻需要兩次的原因是滴某,焦點還在原來的TextInput上面。
解決的辦法就是滋迈,監(jiān)聽軟鍵盤的消失方法霎奢,然后在消失方法里面,再一次調(diào)用軟鍵盤消失方法:
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();
}