[General] Use handler observer API for relation updates#4180
Open
j-piasecki wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression introduced by PR #4179: after gesture creation was deferred to a parent effect, configureRelations ran during the child detector's render before the handler existed on the native side, so the first relations call became a no-op. This PR routes relation configuration through the existing observeHandler API so it is deferred until the handler is actually registered, on all three platforms.
Changes:
- Introduces
useGestureRelationsUpdater(auseMemo+useEffect) and switchesNativeDetector,VirtualDetector, andInterceptingGestureDetectorto use it instead of callingconfigureRelationsduring render. - Refactors
configureRelationsindetectors/utils.tsto return aMap<handlerTag, GestureRelations>rather than pushing directly to the native side, so the hook controls when relations are applied. - Updates the native
configureRelationsentry points (AndroidRNGestureHandlerModule, iOSRNGestureHandlerManager, webRNGestureHandlerModule.web.ts) to subscribe viaobserveHandler/observeHandlerWithTag:, cancelling the observation after the first delivery.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/detectors/useGestureRelationsUpdater.ts | New hook that memoizes the relations map and applies it in an effect. |
| packages/react-native-gesture-handler/src/v3/detectors/NativeDetector.tsx | Replaces inline configureRelations call with the new hook. |
| packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/VirtualDetector.tsx | Same hook replacement for virtual detector. |
| packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx | Replaces conditional inline call with the hook (now safe with undefined gesture). |
| packages/react-native-gesture-handler/src/v3/detectors/utils.ts | configureRelations no longer dispatches to native; returns a tag→relations map and threads it through traversal. |
| packages/react-native-gesture-handler/src/RNGestureHandlerModule.web.ts | Replaces synchronous lookup + early return with NodeManager.observeHandler flow. |
| packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm | Uses registry observeHandlerWithTag: instead of direct handlerWithTag:. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt | Uses registry observeHandler instead of getHandler + early return. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
#4179 changed the timing of gesture creation and attachment, after that change
configureRelationswas being fired before the gesture was created.This PR updates the relations configuration flow to use the observers API.
Test plan
Example app