Skip to content

Commit 7dd2dd2

Browse files
committed
extract updateResponderEventValue
1 parent 24a339b commit 7dd2dd2

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

packages/react-native-gesture-handler/src/v3/components/Pressable.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ import {
4444
useSimultaneousGestures,
4545
} from '../hooks';
4646
import { PureNativeButton } from './GestureButtons';
47-
import { JSResponderContext } from './ScrollViewResponderInterceptor';
47+
import {
48+
JSResponderContext,
49+
updateResponderEventValue,
50+
} from './ScrollViewResponderInterceptor';
4851

4952
const DEFAULT_LONG_PRESS_DURATION = 500;
5053
const IS_TEST_ENV = isTestEnv();
@@ -400,11 +403,7 @@ const Pressable = (props: PressableProps) => {
400403
// when there are no RN responder components between it and this Pressable.
401404
const handleStartShouldSetResponder = useCallback(() => {
402405
if (!disabled) {
403-
const responderEventRef = jsResponderContext?.isRNGHResponderEvent;
404-
405-
if (responderEventRef) {
406-
responderEventRef.current = true;
407-
}
406+
updateResponderEventValue(jsResponderContext, true);
408407
}
409408

410409
return false;

packages/react-native-gesture-handler/src/v3/components/ScrollViewResponderInterceptor.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ export type JSResponderContextValue = {
1010
export const JSResponderContext =
1111
React.createContext<JSResponderContextValue | null>(null);
1212

13+
export function updateResponderEventValue(
14+
jsResponderContext: JSResponderContextValue | null | undefined,
15+
value: boolean
16+
) {
17+
const responderEventRef = jsResponderContext?.isRNGHResponderEvent;
18+
19+
if (responderEventRef) {
20+
responderEventRef.current = value;
21+
}
22+
}
23+
1324
type ScrollViewResponderInterceptorProps = PropsWithChildren<{
1425
keyboardShouldPersistTaps?: RNScrollViewProps['keyboardShouldPersistTaps'];
1526
}>;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { use, useCallback, useEffect, useRef, useState } from 'react';
22

33
import { Reanimated } from '../../handlers/gestures/reanimatedWrapper';
4-
import { JSResponderContext } from '../components/ScrollViewResponderInterceptor';
4+
import {
5+
JSResponderContext,
6+
updateResponderEventValue,
7+
} from '../components/ScrollViewResponderInterceptor';
58
import { type Gesture, type SharedValue, SingleGestureName } from '../types';
69
import { isComposedGesture, isGestureEnabled } from './utils';
710
import {
@@ -103,11 +106,7 @@ export function useJSResponderHandler<
103106

104107
const handleStartShouldSetResponder = useCallback(() => {
105108
if (shouldHandleJSResponderEvent()) {
106-
const responderEventRef = jsResponderContext?.isRNGHResponderEvent;
107-
108-
if (responderEventRef) {
109-
responderEventRef.current = true;
110-
}
109+
updateResponderEventValue(jsResponderContext, true);
111110
}
112111

113112
return false;

0 commit comments

Comments
 (0)