Skip to content

Do not call onPress on buttons while dismissing keyboard#4281

Open
m-bert wants to merge 3 commits into
mainfrom
@mbert/buttons-keyboard
Open

Do not call onPress on buttons while dismissing keyboard#4281
m-bert wants to merge 3 commits into
mainfrom
@mbert/buttons-keyboard

Conversation

@m-bert

@m-bert m-bert commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Description

Currently, when buttons are inside ScrolView with keyboardShouldPersistTaps={never} they still call onPress even 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

Copilot AI review requested due to automatic review settings June 23, 2026 10:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ScrollViewResponderInterceptor and exposed isKeyboardDismissingTap(...) for components to consult.
  • Updated v3 Pressable and Touchable to detect “keyboard dismiss” taps and suppress onPress* callbacks for that interaction.
  • Adjusted v3 API tests and expanded the example app’s keyboardShouldPersistTaps demo to include Touchable.

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.

@m-bert m-bert requested a review from coado June 23, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseButton does not seem to respect TouchableWithoutFeedback

2 participants