Skip to content

Commit

Permalink
Use locationOfTouch:inView over locationInView for focal (softwar…
Browse files Browse the repository at this point in the history
…e-mansion#2833)

Replace `locationInView` with `locationOfTouch:inView:` in Pinch handler
to fix truncated focalX and focalY in gesture handler context.

Tested on repro example in (software-mansion#2833).
  • Loading branch information
rrebase committed Mar 26, 2024
1 parent f4f1907 commit 04747c0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apple/Handlers/RNPinchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,15 @@ - (RNGestureHandlerEventExtraData *)eventExtraData:(NSMagnificationGestureRecogn
#else
- (RNGestureHandlerEventExtraData *)eventExtraData:(UIPinchGestureRecognizer *)recognizer
{
CGPoint accumulatedPoint = CGPointZero;
for (int i = 0; i < recognizer.numberOfTouches; i++) {
CGPoint location = [recognizer locationOfTouch:i inView:recognizer.view];
accumulatedPoint.x += location.x;
accumulatedPoint.y += location.y;
}
CGPoint focalPoint = CGPointMake(accumulatedPoint.x / recognizer.numberOfTouches, accumulatedPoint.y / recognizer.numberOfTouches);
return [RNGestureHandlerEventExtraData forPinch:recognizer.scale
withFocalPoint:[recognizer locationInView:recognizer.view]
withFocalPoint:focalPoint
withVelocity:recognizer.velocity
withNumberOfTouches:recognizer.numberOfTouches
withPointerType:_pointerType];
Expand Down

0 comments on commit 04747c0

Please sign in to comment.