Do not call onPress on buttons while dismissing keyboard#4281
Open
m-bert wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to align RNGH v3 Pressable/Touchable behavior with React Native when used inside a ScrollView with keyboardShouldPersistTaps="never", swallowing the tap that dismisses the soft keyboard so it doesn’t also trigger onPress-family callbacks.
Changes:
- Added shared keyboard-visibility tracking in
ScrollViewResponderInterceptorand exposedisKeyboardDismissingTap(...)for components to consult. - Updated v3
PressableandTouchableto detect “keyboard dismiss” taps and suppressonPress*callbacks for that interaction. - Adjusted v3 API tests and expanded the example app’s
keyboardShouldPersistTapsdemo to includeTouchable.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.tsx | Detects keyboard-dismiss taps via JS responder context and suppresses press callbacks for that gesture. |
| packages/react-native-gesture-handler/src/v3/components/ScrollViewResponderInterceptor.tsx | Adds reference-counted keyboard visibility listeners and exposes isKeyboardDismissingTap based on keyboardShouldPersistTaps and keyboard visibility. |
| packages/react-native-gesture-handler/src/v3/components/Pressable.tsx | Suppresses v3 press handling when the initiating touch is used to dismiss the keyboard. |
| packages/react-native-gesture-handler/src/tests/api_v3.test.tsx | Updates responder-handling assertions to reflect the responder marker flow after Pressable changes. |
| apps/common-app/src/new_api/tests/keyboardShouldPersistTaps/index.tsx | Adds a Touchable variant to the interactive keyboardShouldPersistTaps example. |
Comments suppressed due to low confidence (1)
packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.tsx:196
- When the initial touch is identified as the keyboard-dismissing tap (dropKeyboardTapRef.current === true), onUpdate can still call onPressIn/onPressOut as the finger moves because it doesn't check dropKeyboardTapRef. This means a swallowed tap can still trigger press-in/out side effects, which contradicts the goal of fully swallowing the keyboard-dismiss interaction.
const onUpdate = useCallback(
(e: CallbackEventType) => {
if (pointerState.current === PointerState.UNKNOWN) {
return;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently, when buttons are inside
ScrolViewwithkeyboardShouldPersistTaps={never}they still callonPresseven though press was meant to dismiss keyboard.This PR fixes that behavior. It attaches listeners for keyboard state and based on that it blocks
onPress*callbacks on JS side.Fixes #992
Test plan
Tested on Keyboard Should Persist Taps example