Skip to content

Commit 14e7ac0

Browse files
j-piaseckim-bert
andauthored
Fix double start when activateAfterLongPress is used (#2628)
## Description It seems like native iOS recognizers (or at least Pan) don't respect when their state is changed from outside, which caused a problem with `.activateAfterLongPress` - before sending event in `Active` state, the state of the native recognizer is updated to `UIGestureRecognizerStateBegan`. Despite this, after moving the finger it tries to change the state to `UIGestureRecognizerStateBegan` once more, causing weird `Active` -> `Began`, `Began` -> `Active` chain. This PR adds a simple check to detect the first event and stop processing in case it happens. ~~One thing that *could* be related is the fact that when the gesture fails before activation, the gesture stays in the `Began` state until the finger is lifted. This still needs to be investigated.~~ I think this is a separate issue. Fixes #2620 ## Test plan Tested on the example app. --------- Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
1 parent 7581fde commit 14e7ac0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

apple/RNGestureHandler.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ - (void)sendEventsInState:(RNGestureHandlerState)state
240240
return;
241241
}
242242

243+
// Recognizers don't respect manually changing their state (that happens when we are activating handler
244+
// under custom conditions). If we send a custom event in state ACTIVE and the recognizer will later update its
245+
// state, we will end up sending ACTIVE->BEGAN and BEGAN->ACTIVE chain. To prevent this, we simply detect the first
246+
// weird state change and stop it (then we don't update _lastState), so the second call ends up without state change
247+
// and is fine.
248+
if (state == RNGestureHandlerStateBegan && _lastState == RNGestureHandlerStateActive) {
249+
return;
250+
}
251+
243252
if (state == RNGestureHandlerStateActive) {
244253
// Generate a unique coalescing-key each time the gesture-handler becomes active. All events will have
245254
// the same coalescing-key allowing RCTEventDispatcher to coalesce RNGestureHandlerEvents when events are

0 commit comments

Comments
 (0)