Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismiss Keyboard React-Native

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.

like image 234
zafrani Avatar asked Sep 30 '15 22:09

zafrani


People also ask

How do you dismiss the keyboard in React Native?

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.

How do you close keyboard on button click in React Native?

You can dismiss the keyboard by using Keyboard. dismiss .

How do you check if keyboard is opened React Native?

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.


2 Answers

Use built-in Keyboard Module:

import { Keyboard } from 'react-native';  Keyboard.dismiss();  
like image 127
Chen-Tsu Lin Avatar answered Oct 08 '22 20:10

Chen-Tsu Lin


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();  
like image 21
zafrani Avatar answered Oct 08 '22 18:10

zafrani