[General] Change how gestures are attached to the native detector to fix StrictMode#4179
Open
j-piasecki wants to merge 4 commits into
Open
[General] Change how gestures are attached to the native detector to fix StrictMode#4179j-piasecki wants to merge 4 commits into
j-piasecki wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
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(); |
Member
Author
There was a problem hiding this comment.
I know, I wanted to handle it in a follow-up to keep changes as small as possible
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
Module.createGestureHandlerto be asynchronousNativeProxy.createGestureHandlerto use the same scheduling as drop to preserve relative orderingGestureDetectornot 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, socreate -> drop -> createisn't run ascreate -> create -> drop.Test plan
Use the example app.