1<TouchableWithoutFeedback onPress={Keyboard.dismiss} >
2 <TextInput />
3</TouchableWithoutFeedback>
1 // Step 1: Get Keyboard, TouchableWithoutFeedback from ‘react-native’;
2 import { View, TextInput, StyleSheet, Keyboard, TouchableWithoutFeedback } from 'react-native';
3
4 // Step 2: Create an arrow function to write dismiss keyboard code
5 const DismissKeyboard = ({ children }) => (
6 <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
7 {children}
8 </TouchableWithoutFeedback>
9 );
10
11 // Step 3: Wrap all TextInput inside <DismissKeyboard> </DismissKeyboard>
12 //Example
13 <DismissKeyboard>
14 <View style={styles.container}>
15 <TextInput style={styles.input} placeholder="email" />
16 <TextInput style={styles.input} placeholder="password" />
17 </View>
18 </DismissKeyboard>