APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.24k stars 643 forks source link

Tap to dismiss keyboard #512

Open KrisLau opened 2 years ago

KrisLau commented 2 years ago

I have a KeyboardAwareScrollView surrounding some text inputs. When I click away from a text input, I'm hoping to dismiss the keyboard so I set keyboardShouldPersistTaps={'handled'} but it doesn't seem to dismiss the keyboard

sikandarchishty commented 2 years ago

Use TouchableWithoutFeedback to wrap around your KeyboardAwareScrollView and onPress of TouchableWithoutFeedback add onPress={Keyboard.dismiss} and accessbile={false}

Note: Keyboard, TouchableWithoutFeedback needs to be imported from react-native.

Example:

<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
    <KeyboardAwareScrollView>
        {your code}
    </KeyboardAwareScrollView>
</TouchableWithoutFeedback>
KrisLau commented 2 years ago

@sikandarchishty That works but I feel like that dismissing the keyboard when tapping away should be the default behaviour