A simple way to dismiss the keyboard programmatically in a react native application. A demo app can be found here.
This module extracts code from an undocumented React Native feature. The reason I wrote it is that the import of the internal module failed after updating and in some specific setups. The feature is now documented in React Native and may be used directly with the React Native Keyboard API. If your React Native version is high enough I can only encourage you to use React Natives implementation.
This module targets React Native Views, therefore the solution will not work in React Native Web Views. Please use an alternative solution in your Web Views Javascript.
- Run
npm install react-native-dismiss-keyboard --save
- To import the library choose one of these options
-
var dismissKeyboard = require('react-native-dismiss-keyboard');
-
import dismissKeyboard from 'react-native-dismiss-keyboard';
- Run
anywhere in your code to close the keyboard.
dismissKeyboard()
React Native Version | react-native-dismiss-keyboard Version |
---|---|
>= 0.11 & < 0.23 | < 1.0 |
>= 0.23 | >= 1.0 |
>= 0.36 | React Native Keyboard API |
If you experience any restrictions or if it works on other versions, please let us know.
Please make sure to run the tests before proposing a PR by running npm test
.