React Native Hide Dismiss Keyboard on Touch Outside Example

In react native the Keyboard.dismiss() method is used to hide the keyboard or soft keypad, touchpad on a certain click event. In some of applications we have seen that user can tap outside the TextInput component and automatically the keyboard will hide, there is no need to click on a button or other component to hide the touchpad. This functionality is called as hiding keyboard by touching anywhere on screen. So in this tutorial we would learn about React Native Hide Dismiss Keyboard on Touch Outside Android iOS Example.

Contents in this project React Native Hide Dismiss Keyboard on Touch Outside Example:-

1. Open your project’s main App.js file and import Keyboard, StyleSheet, View, Text, TextInput and TouchableWithoutFeedback component.

2. Creating custom component named as HideKeyboard with children prop. Inside the component we would use the TouchableWithoutFeedback component and apply the onPress={() => Keyboard.dismiss()} event. We would use this component as our Root component below.

3. Creating our main export default App functional component. Here we would first call our custom component HideKeyboard as Root parent component -> creating 2 Text Input components.

4. Creating Style.

5. Complete Source Code for App.js file:

Screenshot:

React Native Hide Dismiss Keyboard on Touch Outside Example