Reputation: 155
I am having problems with my text input component in React Native Android.
If I press the back button (device), the text input stays focused and I cannot click to relaunch the keyboard.
How do I resolve this? I have handled onSubmitEditing and onEndEditing which works fine with the "Done" button. But back messes it up.
Thanks in advance!
Upvotes: 1
Views: 1066
Reputation: 91
you need to fire the keyboard dismiss action in a keyboardWillHide event
this.keyboardWillHide = Platform.OS === 'ios' ?
Keyboard.addListener('keyboardWillHide', this.keyboardWillHide) :
Keyboard.addListener('keyboardDidHide', this.keyboardWillHide);
then in the keyboardWillHide callback , insert the keyboard.dismiss function
keyboardWillHide = () => {
// some code
Keyboard.dismiss();
};
That's work for me in 2021
Upvotes: 0
Reputation: 66
I had the exact same problem, not sure what it is caused by but I solved using this.
var {DeviceEventEmitter} = require('react-native')
var dismissKeyboard = require('react-native-dismiss-keyboard')
DeviceEventEmitter.addListener('keyboardDidHide', dismissKeyboard)
Upvotes: 1