From b0cc18496321e4d1ae4ad47e1c2519592d3ea9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Thu, 12 Dec 2024 13:05:18 +0100 Subject: [PATCH] Fix: cancelled events are not ended when manualActivation is used (#3273) ## Description 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](https://github.com/software-mansion/react-native-gesture-handler/pull/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 Tested on repro from the above-mentioned issue and on repro from this [PR](https://github.com/software-mansion/react-native-gesture-handler/pull/3007) --- apple/Handlers/RNFlingHandler.m | 1 - apple/Handlers/RNForceTouchHandler.m | 1 - apple/Handlers/RNLongPressHandler.m | 1 - apple/Handlers/RNManualHandler.m | 1 - apple/Handlers/RNPanHandler.m | 3 --- apple/Handlers/RNPinchHandler.m | 1 - apple/Handlers/RNRotationHandler.m | 1 - apple/Handlers/RNTapHandler.m | 1 - apple/RNManualActivationRecognizer.m | 1 + 9 files changed, 1 insertion(+), 10 deletions(-) diff --git a/apple/Handlers/RNFlingHandler.m b/apple/Handlers/RNFlingHandler.m index 1ca5ad2b8f..554aba88e4 100644 --- a/apple/Handlers/RNFlingHandler.m +++ b/apple/Handlers/RNFlingHandler.m @@ -60,7 +60,6 @@ - (void)touchesCancelled:(NSSet *)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 diff --git a/apple/Handlers/RNForceTouchHandler.m b/apple/Handlers/RNForceTouchHandler.m index 5334c81575..63248a42ff 100644 --- a/apple/Handlers/RNForceTouchHandler.m +++ b/apple/Handlers/RNForceTouchHandler.m @@ -115,7 +115,6 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)ev { [super touchesCancelled:touches withEvent:event]; [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event]; - [self reset]; } - (void)handleForceWithTouches:(NSSet *)touches diff --git a/apple/Handlers/RNLongPressHandler.m b/apple/Handlers/RNLongPressHandler.m index 35dec5aee4..23b2613089 100644 --- a/apple/Handlers/RNLongPressHandler.m +++ b/apple/Handlers/RNLongPressHandler.m @@ -108,7 +108,6 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)ev { [super touchesCancelled:touches withEvent:event]; [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event]; - [self reset]; } #else diff --git a/apple/Handlers/RNManualHandler.m b/apple/Handlers/RNManualHandler.m index 6e4fb5eed1..79474bd16a 100644 --- a/apple/Handlers/RNManualHandler.m +++ b/apple/Handlers/RNManualHandler.m @@ -81,7 +81,6 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)ev { [super touchesCancelled:touches withEvent:event]; [_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event]; - [self reset]; } #else diff --git a/apple/Handlers/RNPanHandler.m b/apple/Handlers/RNPanHandler.m index 201302ab20..8b8c4bdc1b 100644 --- a/apple/Handlers/RNPanHandler.m +++ b/apple/Handlers/RNPanHandler.m @@ -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 diff --git a/apple/Handlers/RNPinchHandler.m b/apple/Handlers/RNPinchHandler.m index 8a69d58156..dd61b991d1 100644 --- a/apple/Handlers/RNPinchHandler.m +++ b/apple/Handlers/RNPinchHandler.m @@ -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 diff --git a/apple/Handlers/RNRotationHandler.m b/apple/Handlers/RNRotationHandler.m index 20a60b9aee..82b14fa7f1 100644 --- a/apple/Handlers/RNRotationHandler.m +++ b/apple/Handlers/RNRotationHandler.m @@ -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 diff --git a/apple/Handlers/RNTapHandler.m b/apple/Handlers/RNTapHandler.m index cada436b54..d10c05a5ef 100644 --- a/apple/Handlers/RNTapHandler.m +++ b/apple/Handlers/RNTapHandler.m @@ -206,7 +206,6 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)ev { [super touchesCancelled:touches withEvent:event]; [self interactionsCancelled:touches withEvent:event]; - [self reset]; } #endif diff --git a/apple/RNManualActivationRecognizer.m b/apple/RNManualActivationRecognizer.m index 355a44ef36..0b96541f2e 100644 --- a/apple/RNManualActivationRecognizer.m +++ b/apple/RNManualActivationRecognizer.m @@ -71,6 +71,7 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)ev [super touchesCancelled:touches withEvent:event]; _activePointers = 0; + self.state = UIGestureRecognizerStateCancelled; [self reset]; }