@@ -16,7 +16,10 @@ const styles = StyleSheet.create({
16
16
} ,
17
17
} ) ;
18
18
19
- type Props < T > = Omit < FlatListProps < T > , 'maintainVisibleContentPosition' > & {
19
+ export type Props < T > = Omit <
20
+ FlatListProps < T > ,
21
+ 'maintainVisibleContentPosition'
22
+ > & {
20
23
/**
21
24
* Called once when the scroll position gets close to end of list. This must return a promise.
22
25
* You can `onEndReachedThreshold` as distance from end of list, when this function should be called.
@@ -27,7 +30,7 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
27
30
* You can `onStartReachedThreshold` as distance from beginning of list, when this function should be called.
28
31
*/
29
32
onStartReached : ( ) => Promise < void > ;
30
- /** Color or inline loading indicator */
33
+ /** Color for inline loading indicator */
31
34
activityIndicatorColor ?: string ;
32
35
/**
33
36
* Enable autoScrollToTop.
@@ -56,7 +59,6 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
56
59
/** Custom UI component for footer indicator of FlatList. Only used when `showDefaultLoadingIndicators` is false */
57
60
ListFooterComponent ?: React . ComponentType ;
58
61
} ;
59
-
60
62
/**
61
63
* Note:
62
64
* - `onEndReached` and `onStartReached` must return a promise.
@@ -67,20 +69,19 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
67
69
* - doesn't accept `ListHeaderComponent` via prop, since it is occupied by `HeaderLoadingIndicator`
68
70
* Set `showDefaultLoadingIndicators` to use `ListHeaderComponent`.
69
71
*/
70
- const BidirectionalFlatList = React . forwardRef (
71
- (
72
- // TODO: Fix typescript generics for ref forwarding.
73
- props : Props < any > ,
72
+ export const BidirectionalFlatList = ( React . forwardRef (
73
+ < T extends any > (
74
+ props : Props < T > ,
74
75
ref :
75
- | ( ( instance : FlatListType | null ) => void )
76
- | MutableRefObject < FlatListType | null >
76
+ | ( ( instance : FlatListType < T > | null ) => void )
77
+ | MutableRefObject < FlatListType < T > | null >
77
78
| null
78
79
) => {
79
80
const {
80
81
activityIndicatorColor = 'black' ,
82
+ autoscrollToTopThreshold = 100 ,
81
83
data,
82
84
enableAutoscrollToTop,
83
- autoscrollToTopThreshold = 100 ,
84
85
FooterLoadingIndicator,
85
86
HeaderLoadingIndicator,
86
87
ListHeaderComponent,
@@ -227,15 +228,14 @@ const BidirectionalFlatList = React.forwardRef(
227
228
228
229
return (
229
230
< >
230
- < FlatList
231
+ < FlatList < T >
231
232
{ ...props }
232
233
ref = { ref }
233
234
progressViewOffset = { 50 }
234
235
ListHeaderComponent = { renderHeaderLoadingIndicator }
235
236
ListFooterComponent = { renderFooterLoadingIndicator }
236
237
onEndReached = { null }
237
238
onScroll = { handleScroll }
238
- // @ts -ignore
239
239
maintainVisibleContentPosition = { {
240
240
autoscrollToTopThreshold : enableAutoscrollToTop
241
241
? autoscrollToTopThreshold
@@ -246,6 +246,8 @@ const BidirectionalFlatList = React.forwardRef(
246
246
</ >
247
247
) ;
248
248
}
249
- ) ;
249
+ ) as unknown ) as BidirectionalFlatListType ;
250
250
251
- export { BidirectionalFlatList as FlatList } ;
251
+ type BidirectionalFlatListType = < T extends any > (
252
+ props : Props < T >
253
+ ) => React . ReactElement ;
0 commit comments