When i press an input in react-native , the keyboard pops an opens. I would like to close the keyboard (ONLY) when pressing some button. How can i do this?
You can dismiss the keyboard by using Keyboard. dismiss .
Method 2: Using ScrollView: We will make use of the ScrollView component along with the keyboardShouldPersistTaps='handled' attribute as the outermost view for our application. This will enable us to dismiss the keyboard whenever we tap on the screen apart from the buttons and text input regions.
Use android:windowSoftInputMode="adjustResize". KeyboardAvoidingView and other keyboard-related components don't work quite well if you have "adjustPan" set for your android:windowSoftInputMode in AndroidManifest. xml . Instead, you should use "adjustResize" and have a wonderful life.
To unfocus a TextInput in React Native, we can use the Keyboard. dismiss method. to set the onSubmitEditing prop to Keyboard. dismiss .
You can dismiss the keyboard by using Keyboard.dismiss
.
import { Keyboard } from 'react-native';
<Touchable onPress={Keyboard.dismiss}>...</Touchable>
If you're using a ScrollView
you'll need to set keyboardShouldPersistTaps
prop to true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With