1
1
import * as React from 'react' ;
2
- import { PropsWithChildren } from 'react' ;
2
+ import {
3
+ PropsWithChildren ,
4
+ ForwardedRef ,
5
+ RefAttributes ,
6
+ ReactElement ,
7
+ } from 'react' ;
3
8
import {
4
9
ScrollView as RNScrollView ,
5
10
ScrollViewProps as RNScrollViewProps ,
@@ -24,63 +29,42 @@ export const ScrollView = createNativeWrapper<
24
29
shouldCancelWhenOutside : false ,
25
30
} ) ;
26
31
// backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457
32
+ // include methods of wrapped components by creating an intersection type with the RN component instead of duplicating them.
27
33
// eslint-disable-next-line @typescript-eslint/no-redeclare
28
- export type ScrollView = typeof ScrollView & {
29
- scrollTo (
30
- y ?: number | { x ?: number ; y ?: number ; animated ?: boolean } ,
31
- x ?: number ,
32
- animated ?: boolean
33
- ) : void ;
34
- scrollToEnd ( options ?: { animated : boolean } ) : void ;
35
- } ;
34
+ export type ScrollView = typeof ScrollView & RNScrollView ;
36
35
37
36
export const Switch = createNativeWrapper < RNSwitchProps > ( RNSwitch , {
38
37
shouldCancelWhenOutside : false ,
39
38
shouldActivateOnStart : true ,
40
39
disallowInterruption : true ,
41
40
} ) ;
42
41
// eslint-disable-next-line @typescript-eslint/no-redeclare
43
- export type Switch = typeof Switch ;
42
+ export type Switch = typeof Switch & RNSwitch ;
44
43
45
44
export const TextInput = createNativeWrapper < RNTextInputProps > ( RNTextInput ) ;
46
45
// eslint-disable-next-line @typescript-eslint/no-redeclare
47
- export type TextInput = typeof TextInput ;
46
+ export type TextInput = typeof TextInput & RNTextInput ;
48
47
49
48
export const DrawerLayoutAndroid = createNativeWrapper <
50
49
PropsWithChildren < RNDrawerLayoutAndroidProps >
51
50
> ( RNDrawerLayoutAndroid , { disallowInterruption : true } ) ;
52
- // we use literal object since TS gives error when using RN's `positions`
53
- // @ts -ignore FIXME(TS) maybe this should be removed?
54
- DrawerLayoutAndroid . positions = { Left : 'left' , Right : 'right' } ;
55
51
// eslint-disable-next-line @typescript-eslint/no-redeclare
56
- export type DrawerLayoutAndroid = typeof DrawerLayoutAndroid ;
52
+ export type DrawerLayoutAndroid = typeof DrawerLayoutAndroid &
53
+ RNDrawerLayoutAndroid ;
57
54
58
- export const FlatList = React . forwardRef < RNFlatList < any > , RNFlatListProps < any > > (
59
- ( props , ref ) => (
60
- < RNFlatList
61
- ref = { ref }
62
- { ...props }
63
- renderScrollComponent = { ( scrollProps ) => < ScrollView { ...scrollProps } /> }
64
- />
65
- )
66
- ) ;
55
+ export const FlatList = React . forwardRef ( ( props , ref ) => (
56
+ < RNFlatList
57
+ ref = { ref }
58
+ { ...props }
59
+ renderScrollComponent = { ( scrollProps ) => < ScrollView { ...scrollProps } /> }
60
+ />
61
+ ) ) as < ItemT = any > (
62
+ props : PropsWithChildren <
63
+ RNFlatListProps < ItemT > &
64
+ RefAttributes < FlatList < ItemT > > &
65
+ NativeViewGestureHandlerProps
66
+ > ,
67
+ ref : ForwardedRef < FlatList < ItemT > >
68
+ ) => ReactElement | null ;
67
69
// eslint-disable-next-line @typescript-eslint/no-redeclare
68
- export type FlatList < ItemT > = React . ComponentType <
69
- RNFlatListProps < ItemT > &
70
- NativeViewGestureHandlerProps &
71
- React . RefAttributes < any >
72
- > & {
73
- scrollToEnd : ( params ?: { animated ?: boolean } ) => void ;
74
- scrollToIndex : ( params : {
75
- animated ?: boolean ;
76
- index : number ;
77
- viewOffset ?: number ;
78
- viewPosition ?: number ;
79
- } ) => void ;
80
- scrollToItem : ( params : {
81
- animated ?: boolean ;
82
- item : ItemT ;
83
- viewPosition ?: number ;
84
- } ) => void ;
85
- scrollToOffset : ( params : { animated ?: boolean ; offset : number } ) => void ;
86
- } ;
70
+ export type FlatList < ItemT = any > = typeof FlatList & RNFlatList < ItemT > ;
0 commit comments