From 9be492e9a2391fdc845f4b4d973c9ad467887b03 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 10 Oct 2023 15:23:58 +0200 Subject: [PATCH 1/2] Fix double start when `activateAfterLongPress` is used --- ios/RNGestureHandler.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ios/RNGestureHandler.m b/ios/RNGestureHandler.m index ac9c7c69d2..fd69738011 100644 --- a/ios/RNGestureHandler.m +++ b/ios/RNGestureHandler.m @@ -224,6 +224,15 @@ - (void)sendEventsInState:(RNGestureHandlerState)state return; } + // When activating a handler under custom conditions (like activateAfterLongPress) recognizers don't respect + // manually changing their state, if we send a custom event in state ACTIVE and the recognizer will later update its + // state, we will end up sending ACTIVE->BEGAN and BEGAN->ACTIVE chain. To prevent this, we simply detect the first + // weird state change and stop it (then we don't update _lastState), so the second call ends up without state change + // and is fine. + if (state == RNGestureHandlerStateBegan && _lastState == RNGestureHandlerStateActive) { + return; + } + if (state == RNGestureHandlerStateActive) { // Generate a unique coalescing-key each time the gesture-handler becomes active. All events will have // the same coalescing-key allowing RCTEventDispatcher to coalesce RNGestureHandlerEvents when events are From f69d233c56d30931a907855c87d2a88b3fad2821 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 21 Dec 2023 12:33:54 +0100 Subject: [PATCH 2/2] Update apple/RNGestureHandler.m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Bert <63123542+m-bert@users.noreply.github.com> --- apple/RNGestureHandler.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apple/RNGestureHandler.m b/apple/RNGestureHandler.m index e15d832d12..07e56c1359 100644 --- a/apple/RNGestureHandler.m +++ b/apple/RNGestureHandler.m @@ -240,8 +240,8 @@ - (void)sendEventsInState:(RNGestureHandlerState)state return; } - // When activating a handler under custom conditions (like activateAfterLongPress) recognizers don't respect - // manually changing their state, if we send a custom event in state ACTIVE and the recognizer will later update its + // Recognizers don't respect manually changing their state (that happens when we are activating handler + // under custom conditions). If we send a custom event in state ACTIVE and the recognizer will later update its // state, we will end up sending ACTIVE->BEGAN and BEGAN->ACTIVE chain. To prevent this, we simply detect the first // weird state change and stop it (then we don't update _lastState), so the second call ends up without state change // and is fine.