From e99edb982ad6293485ea40a1e3637caf40d8d384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Wed, 5 Aug 2026 17:00:57 +0200 Subject: [PATCH 1/2] Wait for custom criteria --- .../apple/Handlers/RNPanHandler.m | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m b/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m index d762cbde63..b4e6e8dafb 100644 --- a/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m +++ b/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m @@ -42,7 +42,9 @@ - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler; @implementation RNBetterPanGestureRecognizer { __weak RNGestureHandler *_gestureHandler; -#if !TARGET_OS_OSX +#if TARGET_OS_OSX + BOOL _blockAutomaticActivation; +#else NSUInteger _realMinimumNumberOfTouches; #endif BOOL _hasCustomActivationCriteria; @@ -114,6 +116,9 @@ - (void)tryUpdateStylusData:(UIEvent *)event - (void)activateAfterLongPress { +#if TARGET_OS_OSX + _blockAutomaticActivation = NO; +#endif self.state = UIGestureRecognizerStateBegan; // Send event in ACTIVE state because UIGestureRecognizerStateBegan is mapped to RNGestureHandlerStateBegan [_gestureHandler handleGesture:self inState:RNGestureHandlerStateActive]; @@ -144,6 +149,11 @@ - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event #endif #if TARGET_OS_OSX + // NSPanGestureRecognizer transitions to the Began state on mouse-down, without any + // built-in movement hysteresis. To honor the custom activation criteria (minDist, + // activeOffsets, minVelocity) we hold the recognizer in the Possible state (see the + // setState: override) until they are met in interactionsMoved. + _blockAutomaticActivation = _hasCustomActivationCriteria; [super mouseDown:event]; #else [super touchesBegan:touches withEvent:event]; @@ -181,7 +191,14 @@ - (void)interactionsMoved:(NSSet *)touches withEvent:(UIEvent *)event } } -#if !TARGET_OS_TV && !TARGET_OS_OSX +#if TARGET_OS_OSX + if (_hasCustomActivationCriteria && self.state == UIGestureRecognizerStatePossible && + [self shouldActivateUnderCustomCriteria]) { + _blockAutomaticActivation = NO; + self.state = UIGestureRecognizerStateBegan; + [self setTranslation:CGPointMake(0, 0) inView:self.view]; + } +#elif !TARGET_OS_TV if (_hasCustomActivationCriteria && self.state == UIGestureRecognizerStatePossible && [self shouldActivateUnderCustomCriteria]) { super.minimumNumberOfTouches = _realMinimumNumberOfTouches; @@ -214,6 +231,23 @@ - (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event #if TARGET_OS_OSX +- (void)setState:(NSGestureRecognizerState)state +{ + if (_blockAutomaticActivation) { + if (state == NSGestureRecognizerStateBegan || state == NSGestureRecognizerStateChanged) { + // Hold the recognizer in the Possible state until the custom activation criteria + // are met — the superclass keeps tracking the mouse regardless, so translation + // and velocity stay valid for the criteria checks. + return; + } + if (state == NSGestureRecognizerStateEnded) { + // Mouse released before the activation criteria were met — the gesture failed. + state = NSGestureRecognizerStateFailed; + } + } + [super setState:state]; +} + - (void)mouseDown:(NSEvent *)event { [_gestureHandler setCurrentPointerTypeToMouse]; @@ -269,6 +303,9 @@ - (void)reset [self triggerActionFromReset]; [_gestureHandler.pointerTracker reset]; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(activateAfterLongPress) object:nil]; +#if TARGET_OS_OSX + _blockAutomaticActivation = NO; +#endif [super reset]; [_gestureHandler reset]; From ec6bee704fdedc97d8ccf0410c831a606fa4a68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Wed, 5 Aug 2026 17:22:44 +0200 Subject: [PATCH 2/2] comment --- .../apple/Handlers/RNPanHandler.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m b/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m index b4e6e8dafb..e67d02cf8c 100644 --- a/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m +++ b/packages/react-native-gesture-handler/apple/Handlers/RNPanHandler.m @@ -151,8 +151,8 @@ - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event #if TARGET_OS_OSX // NSPanGestureRecognizer transitions to the Began state on mouse-down, without any // built-in movement hysteresis. To honor the custom activation criteria (minDist, - // activeOffsets, minVelocity) we hold the recognizer in the Possible state (see the - // setState: override) until they are met in interactionsMoved. + // activeOffsets, minVelocity) we hold the recognizer in the Possible state until + // they are met in interactionsMoved. _blockAutomaticActivation = _hasCustomActivationCriteria; [super mouseDown:event]; #else