Skip to content

[Native] Fix buttons staying pressed in after detached from window#4188

Merged
j-piasecki merged 2 commits into
mainfrom
@jpiasecki/fix-buttons-pressed-in-on-detach
May 22, 2026
Merged

[Native] Fix buttons staying pressed in after detached from window#4188
j-piasecki merged 2 commits into
mainfrom
@jpiasecki/fix-buttons-pressed-in-on-detach

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

Clear up the button state when it's being detached from the window. This prevents the button from staying in the "pressed" state after being reattached.

It also clears up the static responder fields, so the detached buttons cannot prevent others from running interactions.

Test plan

Tested on the reproduction provided by @tomekzaw.

Copilot AI review requested due to automatic review settings May 22, 2026 08:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 addresses a native “stuck pressed” visual/interaction state for RNGestureHandlerButton when the view is detached from its window, ensuring the button resets back to its default (non-pressed) state and doesn’t block other interactions after being reattached.

Changes:

  • iOS/macOS: reset button animation state on window detach.
  • Android: reset button animation state on view detach and clear static responder references tied to the detached instance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm Resets button animation state when the control is removed from the window.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt Resets animation state on detach and clears static responder fields so detached buttons don’t keep global responder ownership.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 736 to +742
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
pendingPressOut?.let { handler.removeCallbacks(it) }
pendingPressOut = null
currentAnimator?.cancel()
currentAnimator = null
applyStartAnimationState()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that:

  • isPointerInsideBounds will reset itself in onTouchEvent
  • isTouched should be reset by the handler being canceled
  • isPressed is mostly managed by the OS, and not resetting it wasn't causing us any problems in the past

@j-piasecki j-piasecki marked this pull request as ready for review May 22, 2026 09:11
Copy link
Copy Markdown
Collaborator

@m-bert m-bert left a comment

Choose a reason for hiding this comment

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

I don't have reproduction from @tomekzaw, but I trust you that it works 😄

@j-piasecki j-piasecki merged commit 267b5a9 into main May 22, 2026
6 checks passed
@j-piasecki j-piasecki deleted the @jpiasecki/fix-buttons-pressed-in-on-detach branch May 22, 2026 11:11
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.

4 participants