Skip to content

Commit a8549b0

Browse files
committed
Keep intercepting gesture detector value stable
1 parent 8bde66d commit a8549b0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
GestureHandlerEvent,
66
DetectorCallbacks,
77
} from '../../types';
8-
import { DetectorContext } from './useDetectorContext';
8+
import { DetectorContext, DetectorContextValue } from './useDetectorContext';
99
import { Reanimated } from '../../../handlers/gestures/reanimatedWrapper';
1010
import { configureRelations, ensureNativeDetectorComponent } from '../utils';
1111
import { isComposedGesture } from '../../hooks/utils/relationUtils';
@@ -64,6 +64,14 @@ export function InterceptingGestureDetector<THandlerData, TConfig>({
6464
setVirtualChildren((prev) => prev.filter((c) => c.viewTag !== childTag));
6565
}, []);
6666

67+
const contextValue: DetectorContextValue = useMemo(
68+
() => ({
69+
register,
70+
unregister,
71+
}),
72+
[register, unregister]
73+
);
74+
6775
// It might happen only with ReanimatedNativeDetector
6876
if (!NativeDetectorComponent) {
6977
throw new Error(
@@ -145,7 +153,7 @@ export function InterceptingGestureDetector<THandlerData, TConfig>({
145153
}
146154

147155
return (
148-
<DetectorContext value={{ register, unregister }}>
156+
<DetectorContext value={contextValue}>
149157
<NativeDetectorComponent
150158
// @ts-ignore This is a type mismatch between RNGH types and RN Codegen types
151159
onGestureHandlerStateChange={handleGestureEvent(

packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/useDetectorContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createContext, use } from 'react';
22
import { VirtualChild } from '../../types';
33

4-
type DetectorContextType = {
4+
export type DetectorContextValue = {
55
register: (child: VirtualChild) => void;
66
unregister: (child: number) => void;
77
};
88

9-
export const DetectorContext = createContext<DetectorContextType | null>(null);
9+
export const DetectorContext = createContext<DetectorContextValue | null>(null);
1010

1111
export function useDetectorContext() {
1212
const ctx = use(DetectorContext);

0 commit comments

Comments
 (0)