Skip to content

[General] Change how gestures are attached to the native detector to fix StrictMode#4179

Open
j-piasecki wants to merge 4 commits into
mainfrom
@jpiasecki/fix-strict-mode
Open

[General] Change how gestures are attached to the native detector to fix StrictMode#4179
j-piasecki wants to merge 4 commits into
mainfrom
@jpiasecki/fix-strict-mode

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

  1. Changes Module.createGestureHandler to be asynchronous
  2. Changes NativeProxy.createGestureHandler to use the same scheduling as drop to preserve relative ordering
  3. Moves the creation of the native handler to the effect from the render phase
  4. Updates the native implementations of GestureDetector not to rely on synchronous creation of gesture handlers. Instead, introduces the ability to register a callback to be fired once a gesture is created. This way, the detector can attach gestures as they are created on the native side with no dependency on JS (the only required thing is the relative ordering of create and drop operations, so create -> drop -> create isn't run as create -> create -> drop.

Test plan

Use the example app.

Copilot AI review requested due to automatic review settings May 18, 2026 10:39
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 changes gesture handler creation/attachment so native detectors no longer depend on synchronous handler creation, aiming to support React StrictMode ordering.

Changes:

  • Defers native handler creation and aligns it with the scheduled operation queue.
  • Adds observer/ready-callback registries for web, Android, and iOS.
  • Updates native/web detector attachment flows to subscribe to handler creation and attach once handlers are available.

Reviewed changes

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

Show a summary per file
File Description
packages/react-native-gesture-handler/src/web/tools/NodeManager.ts Adds handler existence checks and observer registration/cancellation.
packages/react-native-gesture-handler/src/v3/NativeProxy.ts Schedules handler creation through the flush queue.
packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts Moves native handler creation from render to an effect.
packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx Reworks web detector attachment around handler readiness observers.
packages/react-native-gesture-handler/src/specs/NativeRNGestureHandlerModule.ts Changes createGestureHandler codegen signature from sync boolean to void.
packages/react-native-gesture-handler/src/RNGestureHandlerModule.web.ts Makes web relation configuration tolerate missing handlers.
packages/react-native-gesture-handler/apple/RNGestureHandlerRegistry.h Declares ready-callback observer APIs for iOS.
packages/react-native-gesture-handler/apple/RNGestureHandlerRegistry.m Implements iOS handler observer storage and notification.
packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm Defers iOS handler creation into operation blocks.
packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm Reworks iOS detector subscriptions and attachment to use ready callbacks.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRegistry.kt Adds Android observer registration/cancellation and ready notifications.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt Updates Android create method signature to void.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt Reworks Android detector subscription/attachment lifecycle around handler readiness.

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

Comment on lines +88 to +89
NativeProxy.createGestureHandler(type, handlerTag, {});
scheduleFlushOperations();
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 know, I wanted to handle it in a follow-up to keep changes as small as possible

@j-piasecki j-piasecki requested a review from m-bert May 18, 2026 10:53
@j-piasecki j-piasecki marked this pull request as ready for review May 18, 2026 10:53
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.

2 participants