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.
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?
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.
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
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