diff --git a/packages/react-native-gesture-handler/apple/Handlers/RNPinchHandler.m b/packages/react-native-gesture-handler/apple/Handlers/RNPinchHandler.m index 6aecc80855..be535d5b27 100644 --- a/packages/react-native-gesture-handler/apple/Handlers/RNPinchHandler.m +++ b/packages/react-native-gesture-handler/apple/Handlers/RNPinchHandler.m @@ -163,21 +163,28 @@ - (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; + NSUInteger numberOfTouches = recognizer.numberOfTouches; + + if (numberOfTouches > 0) { + CGPoint accumulatedPoint = CGPointZero; + + for (int i = 0; i < numberOfTouches; i++) { + CGPoint location = [recognizer locationOfTouch:i inView:recognizer.view]; + accumulatedPoint.x += location.x; + accumulatedPoint.y += location.y; + } + + focalPoint = CGPointMake(accumulatedPoint.x / numberOfTouches, accumulatedPoint.y / numberOfTouches); + } else { + // Trackpad pinch gestures may report 0 touches - use the recognizer's location instead + focalPoint = [recognizer locationInView:recognizer.view]; } - CGPoint focalPoint = - CGPointMake(accumulatedPoint.x / recognizer.numberOfTouches, accumulatedPoint.y / recognizer.numberOfTouches); - return [RNGestureHandlerEventExtraData forPinch:recognizer.scale withFocalPoint:focalPoint withVelocity:recognizer.velocity - withNumberOfTouches:recognizer.numberOfTouches + withNumberOfTouches:numberOfTouches withPointerType:_pointerType]; } #endif