Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to keep the keyboard open even when input loses focus/prevent blur on React Native?

Tags:

react-native

I am trying to achieve the same effect as in the native 'notes' app. Basically, I have a text input which covers 95% of the screen and I have a small button at the bottom. Tapping the button once should trigger the button's onPress event. Instead, the tap just blurs the text input and I have to tap again on the button in order to trigger it's onPress event.

I would also like to know how to force the keyboard to stay open even when the input is blurred.

Thanks.

like image 513
eyal83 Avatar asked Nov 19 '15 08:11

eyal83


People also ask

How do I fix my keyboard in React Native?

This issue can be solved by using the keyboardDismissMode='on-drag' property on Scrollview and Content, which will make the keyboard to get disappear automatically on scrolling. Read our article on Why is React Native the best for Mobile App Development?

How do you Unfocus text input?

Wrap the View component that is the parent of the TextInput in a Pressable component and then pass Keyboard. dismiss to the onPress prop. So, if the user taps anywhere outside the TextInput field, it will trigger Keyboard. dismiss , which will result in the TextInput field losing focus and the keyboard being hidden.


1 Answers

Any ScrollView make close you keyboard. If you use nested elements, don't forgot to add a property to the parent scrollView keyboardShouldPersistTaps="always". And add blurOnSubmit={false} for keyboard don't blinked when you submit ended.

<ScrollView keyboardShouldPersistTaps="handled">    

    <ScrollView keyboardShouldPersistTaps="always">
      <TextInput           
        placeholder="First field"
        returnKeyType="next"
        blurOnSubmit={false}
        onSubmitEditing={() => {
          this.textInput.focus();
        }}
      />

      <TxtInput
        placeholder="Second"
        getRef={(e) => {
          this.textInput = e;
        }}
        returnKeyType="done"
      />
    </ScrollView>

</ScrollView>

Work in RN v 0.55.3

like image 66
Andrey Patseiko Avatar answered Sep 19 '22 13:09

Andrey Patseiko