Skip to content

Commit 9a72a5c

Browse files
authored
FlatList & Ref types (#4002)
## Description This PR fixes 2 type issues that were reported via private channel: 1. Type 'FlatList' is not generic 2. Type 'Ref<ScrollView>' is not assignable to type 'RefObject<ScrollView | null> | undefined' ## Test plan `yarn ts-check` <details> <summary>Tested on the following code</summary> ```tsx import React, { forwardRef, useEffect, useRef } from 'react'; import { Text } from 'react-native'; import { FlatList, GestureHandlerRootView, ScrollView, } from 'react-native-gesture-handler'; interface MyComponentProps { title: string; } const MyCustomScrollView = forwardRef<ScrollView, MyComponentProps>( (props, ref) => { return ( <ScrollView ref={ref} style={{ flex: 1 }}> <Text>{props.title}</Text> </ScrollView> ); } ); export default function App() { const scrollViewRef = useRef<ScrollView>(null); const flatListRef = useRef<FlatList<number>>(null); useEffect(() => { setTimeout(() => { console.log(scrollViewRef, flatListRef); }, 1000); }); return ( <GestureHandlerRootView style={{ flex: 1 }}> <MyCustomScrollView ref={scrollViewRef} title="Hello, World!" /> </GestureHandlerRootView> ); } ``` </details>
1 parent 6b2d59d commit 9a72a5c

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,4 @@ export const FlatList = ((props) => {
178178
) => ReactElement | null;
179179

180180
// eslint-disable-next-line @typescript-eslint/no-redeclare
181-
export type FlatList = typeof FlatList & RNFlatList;
181+
export type FlatList<ItemT = any> = typeof FlatList & RNFlatList<ItemT>;

packages/react-native-gesture-handler/src/v3/types/NativeWrapperType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../hooks/gestures/native/NativeTypes';
88

99
export type WrapperSpecificProperties<T = unknown> = {
10-
ref?: React.RefObject<T>;
10+
ref?: React.Ref<T>;
1111
onGestureUpdate_CAN_CAUSE_INFINITE_RERENDER?: (
1212
gesture: NativeGesture
1313
) => void;

0 commit comments

Comments
 (0)