Skip to content

Commit b9e07fa

Browse files
committed
Extract to helper
1 parent 58ccf57 commit b9e07fa

4 files changed

Lines changed: 28 additions & 16 deletions

File tree

packages/react-native-gesture-handler/src/components/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1+
import { Platform } from 'react-native';
2+
13
import type { BaseGesture, GestureRef } from '../handlers/gestures/gesture';
24

5+
type TVProps = {
6+
focusable?: boolean | undefined;
7+
isTVSelectable?: boolean | undefined;
8+
};
9+
10+
/**
11+
* Gesture Handler buttons render the native button component directly, bypassing RN's `<View>` —
12+
* the only place the `focusable` prop is translated into `isTVSelectable`, which actually drives
13+
* tvOS focusability.
14+
*/
15+
export function getTVProps(props: TVProps): TVProps | null {
16+
if (!Platform.isTV) {
17+
return null;
18+
}
19+
20+
return {
21+
isTVSelectable: props.focusable ?? props.isTVSelectable ?? false,
22+
};
23+
}
24+
325
export type RelationPropName =
426
| 'simultaneousWithExternalGesture'
527
| 'requireExternalGestureToFail'

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useRef } from 'react';
22
import { Animated, Platform, StyleSheet } from 'react-native';
33

44
import GestureHandlerButton from '../../components/GestureHandlerButton';
5+
import { getTVProps } from '../../components/utils';
56
import createNativeWrapper from '../createNativeWrapper';
67
import type { NativeHandlerData } from '../hooks/gestures/native/NativeTypes';
78
import type { GestureEndEvent, GestureEvent } from '../types';
@@ -95,11 +96,7 @@ export const BaseButton = (props: BaseButtonProps) => {
9596
props.onFinalize?.(e);
9697
};
9798

98-
const tvProps = Platform.isTV
99-
? {
100-
isTVSelectable: rest.focusable ?? rest.isTVSelectable ?? false,
101-
}
102-
: null;
99+
const tvProps = getTVProps(rest);
103100

104101
return (
105102
<RawButton

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
mockCenterPressableEvent,
3232
numberAsInset,
3333
} from '../../components/Pressable/utils';
34+
import { getTVProps } from '../../components/utils';
3435
import { PressabilityDebugView } from '../../handlers/PressabilityDebugView';
3536
import { useIsScreenReaderEnabled } from '../../useIsScreenReaderEnabled';
3637
import { INT32_MAX, isTestEnv } from '../../utils';
@@ -384,12 +385,7 @@ const Pressable = (props: PressableProps) => {
384385
[onLayout]
385386
);
386387

387-
const tvProps = Platform.isTV
388-
? {
389-
isTVSelectable:
390-
remainingProps.focusable ?? remainingProps.isTVSelectable ?? false,
391-
}
392-
: null;
388+
const tvProps = getTVProps(remainingProps);
393389

394390
return (
395391
<GestureDetector gesture={gesture}>

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useCallback, useRef } from 'react';
22
import { Platform } from 'react-native';
33

44
import GestureHandlerButton from '../../../components/GestureHandlerButton';
5+
import { getTVProps } from '../../../components/utils';
56
import { NativeDetector } from '../../detectors/NativeDetector';
67
import { useNativeGesture } from '../../hooks';
78
import type {
@@ -208,11 +209,7 @@ export const Touchable = (props: TouchableProps) => {
208209
}
209210
: TRANSPARENT_RIPPLE;
210211

211-
const tvProps = Platform.isTV
212-
? {
213-
isTVSelectable: rest.focusable ?? rest.isTVSelectable ?? false,
214-
}
215-
: null;
212+
const tvProps = getTVProps(rest);
216213

217214
return (
218215
<NativeDetector gesture={nativeGesture}>

0 commit comments

Comments
 (0)