From 04747c016c935262d447f91b57dc49778d912b37 Mon Sep 17 00:00:00 2001 From: Ragnar Rebase Date: Tue, 26 Mar 2024 21:14:17 +0200 Subject: [PATCH] Use `locationOfTouch:inView` over `locationInView` for focal (#2833) Replace `locationInView` with `locationOfTouch:inView:` in Pinch handler to fix truncated focalX and focalY in gesture handler context. Tested on repro example in (#2833). --- apple/Handlers/RNPinchHandler.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apple/Handlers/RNPinchHandler.m b/apple/Handlers/RNPinchHandler.m index d4351bea08..c0adeae61a 100644 --- a/apple/Handlers/RNPinchHandler.m +++ b/apple/Handlers/RNPinchHandler.m @@ -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];