Skip to content

[Native] Fix host detector when used alongside Activity#3967

Merged
j-piasecki merged 3 commits intomainfrom
@jpiasecki/fix-native-detector-activity
Feb 10, 2026
Merged

[Native] Fix host detector when used alongside Activity#3967
j-piasecki merged 3 commits intomainfrom
@jpiasecki/fix-native-detector-activity

Conversation

@j-piasecki
Copy link
Member

Description

Fixes #3965

There were two parts to this isse:

  1. currentGestureRef was never reset, so the gesture was never recreated after being dropped
  2. Android implementation didn't handle being attached/detached from window

This PR updates useGesture so that it resets the currentGestureRef after dropping the handler. It also updates the Android implementation of the Host Detector component to store all attached handlers on window detach and reattaches them after window attach.

Test plan

See the reproduction from the linked issue.

Copilot AI review requested due to automatic review settings February 9, 2026 10:07
Copy link
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

Fixes a regression where hook-based gestures stop working when used inside React 19.2 <Activity> on Android by ensuring gesture handlers can be recreated and host-detector-attached handlers survive window detach/attach cycles.

Changes:

  • Reset currentGestureRef when dropping a hook gesture handler so it can be recreated later.
  • Update Android Host Detector view to detach/re-attach handlers on window detach/attach.
  • Switch detector view manager teardown to explicitly detach all handlers on view drop.

Reviewed changes

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

File Description
packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts Resets the stored “current gesture” ref on cleanup to allow handler recreation after dropping.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorViewManager.kt Ensures handlers are detached during view drop via detachAllHandlers().
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt Adds attach/detach window lifecycle handling and expands detachAllHandlers() to include native handlers.

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

Copy link
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

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


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

Copy link
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


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

@j-piasecki j-piasecki merged commit 746564b into main Feb 10, 2026
12 checks passed
@j-piasecki j-piasecki deleted the @jpiasecki/fix-native-detector-activity branch February 10, 2026 09:22
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.

[3.0.0-beta.1] Hook gestures stop working after parent <Activity> changes mode

2 participants