Is there a simple way to hide the iOS keyboard? I want to force it shut in a few specific scenarios that don't necessarily require focusing another view. i.e. like a specific response from the server.
For dismiss keyboard, React Native Keyboard module have dismiss() method, when you call Keyboard. dismiss() on anny event or if keyboard active then it will close keyboard.
You can dismiss the keyboard by using Keyboard. dismiss .
To detect when keyboard is opened or closed in React Native, we can call Keyboard. addListener to listen to the 'keybvoardDidShow' and 'keyboardDidHide' events to watch for the keyboard showing and hiding respectively.
Use built-in Keyboard
Module:
import { Keyboard } from 'react-native'; Keyboard.dismiss();
Was able to achieve this with
import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard'
And then at the point where I need to toggle the keyboard off
dismissKeyboard();
-- -- EDIT -- --
Importing like this works equally as well.
import dismissKeyboard from 'dismissKeyboard'
-- -- EDIT #2 -- --
My original answer is now outdated. The correct way is mentioned below by @Chen-Tsu Lin
import { Keyboard } from 'react-native'; Keyboard.dismiss();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With