Skip to content

Emit coordinates in Native gesture events#4302

Merged
m-bert merged 8 commits into
mainfrom
@mbert/naative-emit-coordinates
Jul 9, 2026
Merged

Emit coordinates in Native gesture events#4302
m-bert merged 8 commits into
mainfrom
@mbert/naative-emit-coordinates

Conversation

@m-bert

@m-bert m-bert commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR adds absolute and relative coordinates to Native gesture events. It alsol preserves current cancelation logic - based on pointerInside.

Test plan

Add console.log to Touchable implementation and check that coordinates are present.

Copilot AI review requested due to automatic review settings July 7, 2026 13:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 extends the Native (NativeView) gesture event payload to include both relative (x, y) and absolute (absoluteX, absoluteY) coordinates across web, iOS/macOS, and Android, while keeping the existing “active update suppression” semantics based on pointer state (e.g., pointerInside).

Changes:

  • Web: add x/y/absoluteX/absoluteY to the transformed native event payload and adjust active-update suppression to ignore coordinate churn.
  • Apple: emit coordinates for NativeView handler events (UIControl + macOS path), and adjust suppression to ignore coordinates.
  • Android: emit coordinates for NativeView handler events (converted to DIP) from existing handler position fields.
  • Types: extend v3 NativeHandlerData to include the new coordinate fields.

Reviewed changes

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

Show a summary per file
File Description
packages/react-native-gesture-handler/src/web/handlers/NativeViewGestureHandler.ts Adds relative/absolute coords to web native events; keeps suppression keyed to pointer state.
packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts Extends v3 NativeHandlerData typing with coordinate fields.
packages/react-native-gesture-handler/apple/RNGestureHandlerEvents.h Updates forPointerInside extra-data factory signature to include coords.
packages/react-native-gesture-handler/apple/RNGestureHandlerEvents.mm Adds coords to forPointerInside payload.
packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm Emits coords for UIControl and macOS native-view events; keeps suppression keyed to pointer state.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/events/eventbuilders/NativeGestureHandlerEventDataBuilder.kt Emits relative/absolute coords (DIP) for native-view events on Android.
Comments suppressed due to low confidence (1)

packages/react-native-gesture-handler/apple/RNGestureHandlerEvents.mm:174

  • forPointerInside:withNumberOfTouches:withPointerType: call sites still exist (e.g. apple/Handlers/RNHoverHandler.m), but this implementation removed that selector. Adding a small forwarding overload here will preserve compatibility and prevent build failures while keeping the new coordinate-aware API.
+ (RNGestureHandlerEventExtraData *)forPointerInside:(BOOL)pointerInside
                                        withPosition:(CGPoint)position
                                withAbsolutePosition:(CGPoint)absolutePosition
                                 withNumberOfTouches:(NSUInteger)numberOfTouches
                                     withPointerType:(NSInteger)pointerType
{
  return [[RNGestureHandlerEventExtraData alloc] initWithData:@{
    @"pointerInside" : @(pointerInside),
    @"x" : @(position.x),
    @"y" : @(position.y),
    @"absoluteX" : @(absolutePosition.x),
    @"absoluteY" : @(absolutePosition.y),
    @"numberOfPointers" : @(numberOfTouches),
    @"pointerType" : @(pointerType)
  }];
}

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

@m-bert
m-bert requested a review from j-piasecki July 7, 2026 15:02
return NO;
RNGHUITouch *touch = [[event allTouches] anyObject];
CGPoint position = touch ? [touch locationInView:sender] : CGPointZero;
CGPoint absolutePosition = touch ? [touch locationInView:nil] : CGPointZero;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
CGPoint absolutePosition = touch ? [touch locationInView:nil] : CGPointZero;
CGPoint absolutePosition = touch ? [touch locationInView:nil] : sender convertPoint:CGPointZero toView:nil];

Shouldn't it be something like this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Probably. 5c2b30f

@m-bert
m-bert requested a review from j-piasecki July 8, 2026 13:44
@m-bert
m-bert merged commit 8b5d4a0 into main Jul 9, 2026
9 checks passed
@m-bert
m-bert deleted the @mbert/naative-emit-coordinates branch July 9, 2026 12:48
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