Skip to content

[General] Use handler observer API for relation updates#4180

Open
j-piasecki wants to merge 1 commit into
@jpiasecki/fix-strict-modefrom
@jpiasecki/observe-for-relation-updates
Open

[General] Use handler observer API for relation updates#4180
j-piasecki wants to merge 1 commit into
@jpiasecki/fix-strict-modefrom
@jpiasecki/observe-for-relation-updates

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

#4179 changed the timing of gesture creation and attachment, after that change configureRelations was being fired before the gesture was created.

This PR updates the relations configuration flow to use the observers API.

Test plan

Example app

@j-piasecki j-piasecki requested a review from Copilot May 18, 2026 11:50
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

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 (a useMemo + useEffect) and switches NativeDetector, VirtualDetector, and InterceptingGestureDetector to use it instead of calling configureRelations during render.
  • Refactors configureRelations in detectors/utils.ts to return a Map<handlerTag, GestureRelations> rather than pushing directly to the native side, so the hook controls when relations are applied.
  • Updates the native configureRelations entry points (Android RNGestureHandlerModule, iOS RNGestureHandlerManager, web RNGestureHandlerModule.web.ts) to subscribe via observeHandler / 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.

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