Skip to content

Commit a8f73c2

Browse files
authored
Update usage of types from React Native to make them compatible with Strict API (#3532)
## Description Updates usage of some types from `react-native` across RNGH codebase. Note: typecheck with the strict api enabled will fail on the codegen types in specs - those are available from the package exports since 0.79. Once this is our lowest supported version, we can update those as well. ## Test plan `yarn ts-check`
1 parent 49bb35f commit a8f73c2

File tree

8 files changed

+28
-17
lines changed

8 files changed

+28
-17
lines changed

packages/react-native-gesture-handler/src/components/DrawerLayout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ export default class DrawerLayout extends Component<
280280
private onGestureEvent?: (
281281
event: GestureEvent<PanGestureHandlerEventPayload>
282282
) => void;
283-
private accessibilityIsModalView = React.createRef<View>();
284-
private pointerEventsView = React.createRef<View>();
283+
private accessibilityIsModalView =
284+
React.createRef<React.ComponentRef<typeof View>>();
285+
private pointerEventsView =
286+
React.createRef<React.ComponentRef<typeof View>>();
285287
private panGestureHandler = React.createRef<PanGestureHandler | null>();
286288
private drawerShown = false;
287289

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export const BaseButton = React.forwardRef<
156156

157157
const AnimatedBaseButton = React.forwardRef<
158158
React.ComponentType,
159-
BaseButtonWithRefProps
159+
Animated.AnimatedProps<BaseButtonWithRefProps>
160160
>((props, ref) => <AnimatedInnerBaseButton innerRef={ref} {...props} />);
161161

162162
const btnStyles = StyleSheet.create({
@@ -193,7 +193,7 @@ class InnerRectButton extends React.Component<RectButtonWithRefProps> {
193193
render() {
194194
const { children, style, ...rest } = this.props;
195195

196-
const resolvedStyle = StyleSheet.flatten(style ?? {});
196+
const resolvedStyle = StyleSheet.flatten(style) ?? {};
197197

198198
return (
199199
<BaseButton
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { View } from 'react-native';
33

4-
export default React.forwardRef<View>((props, ref) => (
5-
<View ref={ref} accessibilityRole="button" {...props} />
6-
));
4+
export default React.forwardRef<React.ComponentRef<typeof View>>(
5+
(props, ref) => <View ref={ref} accessibilityRole="button" {...props} />
6+
);

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ const IS_TEST_ENV = isTestEnv();
4141
let IS_FABRIC: null | boolean = null;
4242

4343
const Pressable = forwardRef(
44-
(props: PressableProps, pressableRef: ForwardedRef<View>) => {
44+
(
45+
props: PressableProps,
46+
pressableRef: ForwardedRef<React.ComponentRef<typeof View>>
47+
) => {
4548
const {
4649
testOnly_pressed,
4750
hitSlop,
@@ -246,7 +249,7 @@ const Pressable = forwardRef(
246249
(delayLongPress ?? DEFAULT_LONG_PRESS_DURATION) +
247250
(unstable_pressDelay ?? 0);
248251

249-
const innerPressableRef = useRef<View>(null);
252+
const innerPressableRef = useRef<React.ComponentRef<typeof View>>(null);
250253

251254
const measureCallback = useCallback(
252255
(width: number, height: number, event: GestureTouchEvent) => {
@@ -309,11 +312,11 @@ const Pressable = forwardRef(
309312
.onTouchesDown((event) => {
310313
handlingOnTouchesDown.current = true;
311314
if (pressableRef) {
312-
(pressableRef as RefObject<View>).current?.measure(
313-
(_x, _y, width, height) => {
314-
measureCallback(width, height, event);
315-
}
316-
);
315+
(
316+
pressableRef as RefObject<React.ComponentRef<typeof View>>
317+
).current?.measure((_x, _y, width, height) => {
318+
measureCallback(width, height, event);
319+
});
317320
} else {
318321
innerPressableRef.current?.measure((_x, _y, width, height) => {
319322
measureCallback(width, height, event);

packages/react-native-gesture-handler/src/components/ReanimatedSwipeable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
269269
simultaneousWithExternalGesture,
270270
requireExternalGestureToFail,
271271
blocksExternalGesture,
272+
hitSlop,
272273
...remainingProps
273274
} = props;
274275

@@ -769,6 +770,7 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
769770
<Animated.View
770771
{...remainingProps}
771772
onLayout={onRowLayout}
773+
hitSlop={hitSlop ?? undefined}
772774
style={[styles.container, containerStyle]}>
773775
{leftElement()}
774776
{rightElement()}

packages/react-native-gesture-handler/src/components/Text.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { GestureObjects as Gesture } from '../handlers/gestures/gestureObjects';
1515
import { GestureDetector } from '../handlers/gestures/GestureDetector';
1616

1717
export const Text = forwardRef(
18-
(props: RNTextProps, ref: ForwardedRef<RNText>) => {
18+
(
19+
props: RNTextProps,
20+
ref: ForwardedRef<React.ComponentRef<typeof RNText>>
21+
) => {
1922
const { onPress, onLongPress, ...rest } = props;
2023

2124
const textRef = useRef<RNText | null>(null);
@@ -46,7 +49,7 @@ export const Text = forwardRef(
4649
}
4750

4851
const textElement = ref
49-
? (ref as RefObject<RNText>).current
52+
? (ref as RefObject<React.ComponentRef<typeof RNText>>).current
5053
: textRef.current;
5154

5255
// At this point we are sure that textElement is div in HTML tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function findNodeHandle(
6060
if (Platform.OS === 'web') {
6161
return node;
6262
}
63-
return findNodeHandleRN(node);
63+
return findNodeHandleRN(node) ?? null;
6464
}
6565
let flushOperationsScheduled = false;
6666

packages/react-native-gesture-handler/src/web_hammer/GestureHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ abstract class GestureHandler {
283283
this.propsRef = propsRef;
284284
this.ref = ref;
285285

286+
// @ts-ignore
286287
this.view = findNodeHandle(ref);
287288

288289
// When the browser starts handling the gesture (e.g. scrolling), it sends a pointercancel event and stops

0 commit comments

Comments
 (0)