diff --git a/packages/react-native-gesture-handler/apple/RNManualActivationRecognizer.m b/packages/react-native-gesture-handler/apple/RNManualActivationRecognizer.m index 2ecaef6e2e..d99b1eed3c 100644 --- a/packages/react-native-gesture-handler/apple/RNManualActivationRecognizer.m +++ b/packages/react-native-gesture-handler/apple/RNManualActivationRecognizer.m @@ -22,24 +22,31 @@ - (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler - (void)handleGesture:(UIGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateBegan) { +#if TARGET_OS_OSX + // On iOS, this recognizer completing is enough to deny the handler's recognizer — + // UIKit fails a recognizer whose required-to-fail dependency recognizes. AppKit + // does not do this reliably: completing the blocker can flush the dependent + // recognizer's buffered recognition instead of discarding it. + _handler.recognizer.state = UIGestureRecognizerStateFailed; +#endif self.state = UIGestureRecognizerStateEnded; [self reset]; } } #if TARGET_OS_OSX -- (void)mouseUp:(NSEvent *)event +- (void)mouseDown:(NSEvent *)event { - [super mouseUp:event]; + [super mouseDown:event]; - _activePointers -= 1; + _activePointers += 1; } -- (void)mouseDown:(NSEvent *)event +- (void)mouseUp:(NSEvent *)event { - [super mouseDown:event]; + [super mouseUp:event]; - _activePointers += 1; + _activePointers -= 1; if (_activePointers == 0) { self.state = UIGestureRecognizerStateBegan; @@ -80,6 +87,7 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)ev - (void)reset { self.enabled = YES; + _activePointers = 0; [super reset]; } @@ -106,4 +114,15 @@ - (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGe return NO; } +#if TARGET_OS_OSX +// On iOS the method above is a UIGestureRecognizer subclass override, called by the system +// to establish the failure requirement. NSGestureRecognizer has no such subclass hook — +// AppKit only consults the delegate, so forward the delegate callback to the shared logic. +- (BOOL)gestureRecognizer:(NSGestureRecognizer *)gestureRecognizer + shouldBeRequiredToFailByGestureRecognizer:(NSGestureRecognizer *)otherGestureRecognizer +{ + return [self shouldBeRequiredToFailByGestureRecognizer:otherGestureRecognizer]; +} +#endif + @end