@@ -16,7 +16,10 @@ const styles = StyleSheet.create({
1616 } ,
1717} ) ;
1818
19- type Props < T > = Omit < FlatListProps < T > , 'maintainVisibleContentPosition' > & {
19+ export type Props < T > = Omit <
20+ FlatListProps < T > ,
21+ 'maintainVisibleContentPosition'
22+ > & {
2023 /**
2124 * Called once when the scroll position gets close to end of list. This must return a promise.
2225 * 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'> & {
2730 * You can `onStartReachedThreshold` as distance from beginning of list, when this function should be called.
2831 */
2932 onStartReached : ( ) => Promise < void > ;
30- /** Color or inline loading indicator */
33+ /** Color for inline loading indicator */
3134 activityIndicatorColor ?: string ;
3235 /**
3336 * Enable autoScrollToTop.
@@ -56,7 +59,6 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
5659 /** Custom UI component for footer indicator of FlatList. Only used when `showDefaultLoadingIndicators` is false */
5760 ListFooterComponent ?: React . ComponentType ;
5861} ;
59-
6062/**
6163 * Note:
6264 * - `onEndReached` and `onStartReached` must return a promise.
@@ -67,20 +69,19 @@ type Props<T> = Omit<FlatListProps<T>, 'maintainVisibleContentPosition'> & {
6769 * - doesn't accept `ListHeaderComponent` via prop, since it is occupied by `HeaderLoadingIndicator`
6870 * Set `showDefaultLoadingIndicators` to use `ListHeaderComponent`.
6971 */
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 > ,
7475 ref :
75- | ( ( instance : FlatListType | null ) => void )
76- | MutableRefObject < FlatListType | null >
76+ | ( ( instance : FlatListType < T > | null ) => void )
77+ | MutableRefObject < FlatListType < T > | null >
7778 | null
7879 ) => {
7980 const {
8081 activityIndicatorColor = 'black' ,
82+ autoscrollToTopThreshold = 100 ,
8183 data,
8284 enableAutoscrollToTop,
83- autoscrollToTopThreshold = 100 ,
8485 FooterLoadingIndicator,
8586 HeaderLoadingIndicator,
8687 ListHeaderComponent,
@@ -227,15 +228,14 @@ const BidirectionalFlatList = React.forwardRef(
227228
228229 return (
229230 < >
230- < FlatList
231+ < FlatList < T >
231232 { ...props }
232233 ref = { ref }
233234 progressViewOffset = { 50 }
234235 ListHeaderComponent = { renderHeaderLoadingIndicator }
235236 ListFooterComponent = { renderFooterLoadingIndicator }
236237 onEndReached = { null }
237238 onScroll = { handleScroll }
238- // @ts -ignore
239239 maintainVisibleContentPosition = { {
240240 autoscrollToTopThreshold : enableAutoscrollToTop
241241 ? autoscrollToTopThreshold
@@ -246,6 +246,8 @@ const BidirectionalFlatList = React.forwardRef(
246246 </ >
247247 ) ;
248248 }
249- ) ;
249+ ) as unknown ) as BidirectionalFlatListType ;
250250
251- export { BidirectionalFlatList as FlatList } ;
251+ type BidirectionalFlatListType = < T extends any > (
252+ props : Props < T >
253+ ) => React . ReactElement ;
0 commit comments