Skip to content

[Native] Use correct coordinate space when using native detector#4137

Merged
j-piasecki merged 4 commits intomainfrom
@jpiasecki/use-correct-coordinate-space
May 4, 2026
Merged

[Native] Use correct coordinate space when using native detector#4137
j-piasecki merged 4 commits intomainfrom
@jpiasecki/use-correct-coordinate-space

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

Currently, all native handlers are using the coordinate space of the view they are attached to for calculating events. If the handler is attached directly to the view (v1, v2, intercepting detector), this is correct, but when the handler is attached to a wrapper (native detector), the coordinates may drift if the child is transformed.

This PR addresses this by using the child of the native detector as the coordinate space base.

Test plan

Tested on #3124

Copilot AI review requested due to automatic review settings April 30, 2026 08:18
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 fixes coordinate drift for native/V3 detector-based gesture handlers by switching event position calculations from the detector wrapper’s coordinate space to the detector child view’s coordinate space (where user-applied transforms live).

Changes:

  • Introduces a coordinateView accessor on iOS (RNGestureHandler) and Android (GestureHandler) to represent the correct coordinate space for reporting event positions.
  • Updates iOS handler event extra-data builders (position / focal point / anchor point) to use coordinateView instead of recognizer.view.
  • Updates Android event transformation, bounds checking, and point transformation to use handler.coordinateView instead of handler.view.

Reviewed changes

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

Show a summary per file
File Description
packages/react-native-gesture-handler/apple/RNGestureHandler.mm Uses coordinateView for base event position reporting and adds coordinateView implementation.
packages/react-native-gesture-handler/apple/RNGestureHandler.h Declares/document coordinateView for iOS handlers.
packages/react-native-gesture-handler/apple/Handlers/RNRotationHandler.m Uses coordinateView for rotation anchor point.
packages/react-native-gesture-handler/apple/Handlers/RNPinchHandler.m Uses coordinateView for pinch focal point (including per-touch averaging).
packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m Uses coordinateView for pan position.
packages/react-native-gesture-handler/apple/Handlers/RNLongPressHandler.m Uses coordinateView for long-press position (iOS + macOS paths).
packages/react-native-gesture-handler/apple/Handlers/RNHoverHandler.m Uses coordinateView for hover position.
packages/react-native-gesture-handler/apple/Handlers/RNForceTouchHandler.m Uses coordinateView for force-touch position.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt Transforms MotionEvents into handler.coordinateView coordinates before delivery.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt Adds coordinateView and uses it for bounds checks and point transforms.

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

Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.mm Outdated
Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.h Outdated
Copy link
Copy Markdown
Collaborator

@m-bert m-bert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.mm
Comment thread packages/react-native-gesture-handler/apple/RNGestureHandler.h Outdated
Copy link
Copy Markdown
Collaborator

@m-bert m-bert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 🚀 I think PR description also should mention VirtualGestureDetector, but it's not that important

@j-piasecki j-piasecki merged commit f1de825 into main May 4, 2026
6 checks passed
@j-piasecki j-piasecki deleted the @jpiasecki/use-correct-coordinate-space branch May 4, 2026 07:55
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 participants