Skip to content

Commit

Permalink
Fix: cancelled events are not ended when manualActivation is used (#3273
Browse files Browse the repository at this point in the history
)

## Description

<!--
Description and motivation for this PR.

Include 'Fixes #<number>' if this is fixing some issue.
-->

Fixes #3239

When the long press gesture is cancelled it is
[forced](https://github.com/software-mansion/react-native-gesture-handler/blob/main/apple/Handlers/RNLongPressHandler.m#L111)
to `reset`. However, base on
[docs](https://developer.apple.com/documentation/uikit/uigesturerecognizer/reset()?changes=l_2&language=objc)
`reset` is also called when the state changes to `failed`, `end` or
`cancelled`, which means that it is called twice, leading to undefined
order of state change events.
~~Base on
[this](#3007)
we can assume that~~ ~~it should only be forced to `reset` if
`manualActivation` is enabled. The same applies to other gestures as
well.~~

The issue here was the effect of not changing the state of
`RNManualActivationRecognizer`
[here](https://github.com/software-mansion/react-native-gesture-handler/blob/main/apple/RNManualActivationRecognizer.m#L69-L75)
to `UIGestureRecognizerStateCancelled`.

## Test plan

<!--
Describe how did you test this change here.
-->

Tested on repro from the above-mentioned issue and on repro from this
[PR](#3007)
  • Loading branch information
coado authored Dec 12, 2024
1 parent 2c7c5b3 commit b0cc184
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 10 deletions.
1 change: 0 additions & 1 deletion apple/Handlers/RNFlingHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

- (void)triggerAction
Expand Down
1 change: 0 additions & 1 deletion apple/Handlers/RNForceTouchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

- (void)handleForceWithTouches:(NSSet<RNGHUITouch *> *)touches
Expand Down
1 change: 0 additions & 1 deletion apple/Handlers/RNLongPressHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#else
Expand Down
1 change: 0 additions & 1 deletion apple/Handlers/RNManualHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#else
Expand Down
3 changes: 0 additions & 3 deletions apple/Handlers/RNPanHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,9 @@ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];

#if !TARGET_OS_TV && !TARGET_OS_OSX
[self tryUpdateStylusData:event];
#endif

[self reset];
}

#if TARGET_OS_OSX
Expand Down
1 change: 0 additions & 1 deletion apple/Handlers/RNPinchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#if TARGET_OS_OSX
Expand Down
1 change: 0 additions & 1 deletion apple/Handlers/RNRotationHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ - (void)interactionsEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)interactionsCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
[self reset];
}

#if TARGET_OS_OSX
Expand Down
1 change: 0 additions & 1 deletion apple/Handlers/RNTapHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
{
[super touchesCancelled:touches withEvent:event];
[self interactionsCancelled:touches withEvent:event];
[self reset];
}

#endif
Expand Down
1 change: 1 addition & 0 deletions apple/RNManualActivationRecognizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
[super touchesCancelled:touches withEvent:event];

_activePointers = 0;
self.state = UIGestureRecognizerStateCancelled;
[self reset];
}

Expand Down

0 comments on commit b0cc184

Please sign in to comment.