Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 until
// they are met in interactionsMoved.
_blockAutomaticActivation = _hasCustomActivationCriteria;
[super mouseDown:event];
#else
[super touchesBegan:touches withEvent:event];
Expand Down Expand Up @@ -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];
}
Comment thread
m-bert marked this conversation as resolved.
Resolved
#elif !TARGET_OS_TV
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (_hasCustomActivationCriteria && self.state == UIGestureRecognizerStatePossible &&
[self shouldActivateUnderCustomCriteria]) {
super.minimumNumberOfTouches = _realMinimumNumberOfTouches;
Expand Down Expand Up @@ -214,6 +231,23 @@ - (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event

#if TARGET_OS_OSX

- (void)setState:(NSGestureRecognizerState)state
Comment thread
j-piasecki marked this conversation as resolved.
Resolved
{
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];
Expand Down Expand Up @@ -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];

Expand Down
Loading