@@ -16,6 +16,7 @@ import {
1616 FlatList as RNFlatList ,
1717 FlatListProps as RNFlatListProps ,
1818 RefreshControl as RNRefreshControl ,
19+ RefreshControlProps as RNRefreshControlProps ,
1920} from 'react-native' ;
2021
2122import createNativeWrapper , {
@@ -27,6 +28,11 @@ import { NativeWrapperProps } from '../hooks/utils';
2728import { DetectorType } from '../detectors' ;
2829import { NativeGesture } from '../hooks/gestures/native/useNativeGesture' ;
2930
31+ export type ImperativeRefreshControlRef = ComponentWrapperRef <
32+ RNRefreshControlProps ,
33+ RNRefreshControl
34+ > | null ;
35+
3036export const RefreshControl = createNativeWrapper (
3137 RNRefreshControl ,
3238 {
@@ -37,7 +43,12 @@ export const RefreshControl = createNativeWrapper(
3743) ;
3844
3945// eslint-disable-next-line @typescript-eslint/no-redeclare
40- export type RefreshControl = typeof RefreshControl & RNRefreshControl ;
46+ export type RefreshControl = RNRefreshControlProps ;
47+
48+ export type ImperativeScrollViewRef = ComponentWrapperRef <
49+ RNScrollViewProps ,
50+ RNScrollView
51+ > | null ;
4152
4253const GHScrollView = createNativeWrapper < PropsWithChildren < RNScrollViewProps > > (
4354 RNScrollView ,
@@ -48,9 +59,6 @@ const GHScrollView = createNativeWrapper<PropsWithChildren<RNScrollViewProps>>(
4859 DetectorType . Intercepting
4960) ;
5061
51- export type ImperativeScrollViewRef =
52- ComponentWrapperRef < RNScrollViewProps > | null ;
53-
5462export const ScrollView = (
5563 props : RNScrollViewProps &
5664 NativeWrapperProperties & {
@@ -65,7 +73,7 @@ export const ScrollView = (
6573 null
6674 ) ;
6775
68- const wrapperRef = useRef < ComponentWrapperRef < RNScrollViewProps > > ( null ) ;
76+ const wrapperRef = useRef < ImperativeScrollViewRef > ( null ) ;
6977
7078 useImperativeHandle < ImperativeScrollViewRef , ImperativeScrollViewRef > (
7179 ref ,
@@ -94,29 +102,40 @@ export const ScrollView = (
94102 />
95103 ) ;
96104} ;
97- // Backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457
98- // include methods of wrapped components by creating an intersection type with the RN component instead of duplicating them.
105+
99106// eslint-disable-next-line @typescript-eslint/no-redeclare
100- export type ScrollView = typeof GHScrollView & RNScrollView ;
107+ export type ScrollView = typeof ScrollView ;
108+
109+ export type ImperativeSwitchRef = ComponentWrapperRef <
110+ RNSwitchProps ,
111+ RNSwitch
112+ > | null ;
101113
102114export const Switch = createNativeWrapper < RNSwitchProps > ( RNSwitch , {
103115 shouldCancelWhenOutside : false ,
104116 shouldActivateOnStart : true ,
105117 disallowInterruption : true ,
106118} ) ;
119+
107120// eslint-disable-next-line @typescript-eslint/no-redeclare
108- export type Switch = typeof Switch & RNSwitch ;
121+ export type Switch = typeof Switch ;
122+
123+ export type ImperativeTextInputRef = ComponentWrapperRef <
124+ RNTextInputProps ,
125+ RNTextInput
126+ > | null ;
109127
110128export const TextInput = createNativeWrapper < RNTextInputProps > ( RNTextInput ) ;
111- // eslint-disable-next-line @typescript-eslint/no-redeclare
112- export type TextInput = typeof TextInput & RNTextInput ;
113129
114130export type ImperativeFlatListRef < T = any > =
115- | ( ComponentWrapperRef < RNScrollViewProps > & {
116- flatListRef : FlatList < T > | null ;
131+ | ( ComponentWrapperRef < RNScrollViewProps , RNScrollView > & {
132+ flatListRef : RNFlatList < T > | null ;
117133 } )
118134 | null ;
119135
136+ // eslint-disable-next-line @typescript-eslint/no-redeclare
137+ export type TextInput = typeof TextInput ;
138+
120139export const FlatList = ( ( props ) => {
121140 const { refreshControl, ref, ...rest } = props ;
122141
@@ -125,7 +144,7 @@ export const FlatList = ((props) => {
125144 ) ;
126145
127146 const wrapperRef = useRef < ImperativeScrollViewRef > ( null ) ;
128- const flatListRef = useRef < FlatList < any > > ( null ) ;
147+ const flatListRef = useRef < RNFlatList < any > > ( null ) ;
129148
130149 const flatListProps = { } ;
131150 const scrollViewProps = { } ;
@@ -191,5 +210,6 @@ export const FlatList = ((props) => {
191210 }
192211 >
193212) => ReactElement | null ;
213+
194214// eslint-disable-next-line @typescript-eslint/no-redeclare
195- export type FlatList < ItemT = any > = typeof FlatList & RNFlatList < ItemT > ;
215+ export type FlatList = typeof FlatList ;
0 commit comments