I need to close a view using setState while closing the keyboard. Using the onBlur event in TextInput, it is working fine. But In android on pressing the hardware back button also keyboard is closing. But onBlur event has not been called. TextInput still focused, but the keyboard closed. For backhander, I am using the following code,
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress = () => {
console.log("HANDLE BACK PRESSS")
return true;
}Also I tried the following - Keyboard.addListener
componentWillMount () {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
}componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
_keyboardDidShow() {
alert('Keyboard Shown');
}
_keyboardDidHide = () => {
alert('Keyboard Hidden');
}But no use. These things are not triggering when the keyboard is in an open state. After the keyboard closed, everything is working as expected.
Suggest some way to get the trigger when pressing the back button while keyboard is in open state.