Skip to content

Commit e1185cd

Browse files
authored
[General] Fix onBegin not being called when the native recognizer skips the BEGAN state (#3932)
## Description The current state machine implementation allows for `onBegin` callback to be skipped if the native recognizer goes from `UNDETERMINED` directly to `ACTIVE` state (which is a valid transition in some cases). This PR updates the logic to "backfill" the `onBegin` callback when receiving the `UNDETERMINED -> ACTIVE` transition, before calling `onActivate`. Note: this PR only changes the behavior for the V3 API. I'm not sure whether it should be backported to V2 as it would likely be a breaking change. ## Test plan This scenario: https://github.com/software-mansion/react-native-gesture-handler/blob/59a5311e3cf517e9147017f20aa41bc644790a05/packages/react-native-gesture-handler/src/components/GestureButtons.tsx#L67-L68
1 parent 6825dbb commit e1185cd

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

packages/react-native-gesture-handler/src/v3/hooks/callbacks/stateChangeHandler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export function getStateChangeHandler<THandlerData>(
3838
(oldState === State.BEGAN || oldState === State.UNDETERMINED) &&
3939
state === State.ACTIVE
4040
) {
41+
// If the native recognizer skipped the BEGAN state, we still need to call the callback
42+
if (oldState === State.UNDETERMINED) {
43+
runCallback(CALLBACK_TYPE.BEGAN, callbacks, event);
44+
}
45+
4146
runCallback(CALLBACK_TYPE.START, callbacks, event);
4247
} else if (oldState !== state && state === State.END) {
4348
if (oldState === State.ACTIVE) {

0 commit comments

Comments
 (0)