Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useMemo, useRef } from 'react';

import { ghQueueMicrotask } from '../../ghQueueMicrotask';
import { getNextHandlerTag } from '../../handlers/getNextHandlerTag';
import {
registerGesture,
Expand Down Expand Up @@ -62,6 +63,7 @@ export function useGesture<
);

const currentGestureRef = useRef({ type: '', handlerTag: -1 });
const dropGestureHandlerTokenRef = useRef(0);
if (
currentGestureRef.current.handlerTag !== handlerTag ||
currentGestureRef.current.type !== (type as string)
Expand Down Expand Up @@ -94,13 +96,26 @@ export function useGesture<
);

useEffect(() => {
// React StrictMode replays effects without re-rendering, while the native
// detector can keep the same handler tag attached during that replay.
// Delay dropping the native handler so the replayed mount can cancel it.
dropGestureHandlerTokenRef.current += 1;
Comment on lines +99 to +101

return () => {
if (currentGestureRef.current.handlerTag === handlerTag) {
currentGestureRef.current = { type: '', handlerTag: -1 };
}
const dropGestureHandlerToken = ++dropGestureHandlerTokenRef.current;

ghQueueMicrotask(() => {
Comment thread
coado marked this conversation as resolved.
if (dropGestureHandlerTokenRef.current !== dropGestureHandlerToken) {
return;
Comment thread
coado marked this conversation as resolved.
}

if (currentGestureRef.current.handlerTag === handlerTag) {
currentGestureRef.current = { type: '', handlerTag: -1 };
}

NativeProxy.dropGestureHandler(handlerTag);
scheduleFlushOperations();
NativeProxy.dropGestureHandler(handlerTag);
scheduleFlushOperations();
});
};
}, [type, handlerTag]);

Expand Down
Loading