Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close keyboard on button press in react-native

Tags:

react-native

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?

like image 989
Vandervidi Avatar asked Jun 27 '16 14:06

Vandervidi


People also ask

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

You can dismiss the keyboard by using Keyboard. dismiss .

How do you dismiss a keyboard in modal React Native?

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.

How do I control my keyboard in React Native?

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.

How do you Unfocus a keyboard in React Native?

To unfocus a TextInput in React Native, we can use the Keyboard. dismiss method. to set the onSubmitEditing prop to Keyboard. dismiss .


1 Answers

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.

like image 192
oblador Avatar answered Oct 06 '22 15:10

oblador