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.
Asked
Active
Viewed 2.1k times
4 Answers
71
Use built-in Keyboard
Module:
import { Keyboard } from 'react-native';
Keyboard.dismiss();

Chen-Tsu Lin
- 22,876
- 16
- 53
- 63
-
1Is there any way to dismiss the keyboard and don't lose the focus? – roadev Jun 24 '17 at 23:26
29
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();

zafrani
- 4,030
- 5
- 31
- 39
-
4From React Native 0.35, there is a Keyboard component that you can use. http://facebook.github.io/react-native/releases/next/docs/keyboard.html. I couldnt however import {Keyboard} from 'react-native' as documentation suggests. I use const {Keyboard} from 'react-native'. – shrutim Nov 23 '16 at 23:23
-
2I down vote this answer, do not because it's incorrect, just because its outdated. Use Keyboard module buildin in RN – neiker Jan 19 '17 at 18:50
2
You may also use this library I wrote: react-native-dismiss-keyboard. It does basically the same as the import of 'dismissKeyboard', but it only uses public API and is therefore safer to use and does not rely on the packager resolving 'dismissKeyboard' as it currently does.

Daniel Schmidt
- 11,605
- 5
- 38
- 70
0
First import Keyboard
import { Keyboard } from 'react-native';
Use:
Keyboard.dismiss();
-
So basically the same solution as the one from this answer: https://stackoverflow.com/a/39772206/1974224 – Cristik Mar 25 '22 at 11:23