@@ -6,7 +6,7 @@ import HeaderMotion, {
66import { Stack } from 'expo-router' ;
77import type { ComponentProps } from 'react' ;
88import { useCallback , useRef } from 'react' ;
9- import { FlatList , StyleSheet , View } from 'react-native' ;
9+ import { StyleSheet , View } from 'react-native' ;
1010import Animated , {
1111 Extrapolation ,
1212 interpolate ,
@@ -16,7 +16,11 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
1616
1717type ListRow = { key : string ; index : number } ;
1818
19- type FL = ComponentProps < typeof FlatList < ListRow > > ;
19+ type FL = ComponentProps < typeof HeaderMotion . FlatList < ListRow > > ;
20+ type FLFn < TKey extends keyof FL > = Extract <
21+ Exclude < FL [ TKey ] , undefined > ,
22+ ( ...args : any [ ] ) => any
23+ > ;
2024
2125const LIST_DATA : ListRow [ ] = Array . from ( { length : 120 } , ( _ , k ) => ( {
2226 key : `row-${ k } ` ,
@@ -37,7 +41,7 @@ export default function Screen() {
3741 />
3842 ) }
3943 </ HeaderMotion . Header >
40- < HeaderMotion . FlatList < ListRow >
44+ < HeaderMotion . FlatList
4145 data = { LIST_DATA }
4246 keyExtractor = { ( item ) => item . key }
4347 renderItem = { ( { item } ) => (
@@ -61,71 +65,62 @@ function useFlatListHandlerLoggers() {
6165 itemVisiblePercentThreshold : 35 ,
6266 } ) . current ;
6367
64- const onViewableItemsChanged = useCallback <
65- NonNullable < FL [ 'onViewableItemsChanged' ] >
66- > ( ( info ) => {
67- console . log ( prefix , 'onViewableItemsChanged' , {
68- viewableCount : info . viewableItems . length ,
69- changedCount : info . changed . length ,
70- firstVisibleIndex : info . viewableItems [ 0 ] ?. index ,
71- } ) ;
72- } , [ ] ) ;
68+ const onViewableItemsChanged = useCallback < FLFn < 'onViewableItemsChanged' > > (
69+ ( info ) => {
70+ console . log ( prefix , 'onViewableItemsChanged' , {
71+ viewableCount : info . viewableItems . length ,
72+ changedCount : info . changed . length ,
73+ firstVisibleIndex : info . viewableItems [ 0 ] ?. index ,
74+ } ) ;
75+ } ,
76+ [ ]
77+ ) ;
7378
7479 return {
75- onScrollBeginDrag : useCallback < NonNullable < FL [ 'onScrollBeginDrag' ] > > (
76- ( e ) => {
77- console . log ( prefix , 'onScrollBeginDrag' , {
78- y : e . nativeEvent . contentOffset . y ,
79- } ) ;
80- } ,
81- [ ]
82- ) ,
83- onScrollEndDrag : useCallback < NonNullable < FL [ 'onScrollEndDrag' ] > > ( ( e ) => {
80+ onScrollBeginDrag : useCallback < FLFn < 'onScrollBeginDrag' > > ( ( e ) => {
81+ console . log ( prefix , 'onScrollBeginDrag' , {
82+ y : e . nativeEvent . contentOffset . y ,
83+ } ) ;
84+ } , [ ] ) ,
85+ onScrollEndDrag : useCallback < FLFn < 'onScrollEndDrag' > > ( ( e ) => {
8486 console . log ( prefix , 'onScrollEndDrag' , {
8587 y : e . nativeEvent . contentOffset . y ,
8688 } ) ;
8789 } , [ ] ) ,
88- onMomentumScrollBegin : useCallback <
89- NonNullable < FL [ 'onMomentumScrollBegin' ] >
90- > ( ( e ) => {
90+ onMomentumScrollBegin : useCallback < FLFn < 'onMomentumScrollBegin' > > ( ( e ) => {
9191 console . log ( prefix , 'onMomentumScrollBegin' , {
9292 y : e . nativeEvent . contentOffset . y ,
9393 } ) ;
9494 } , [ ] ) ,
95- onMomentumScrollEnd : useCallback < NonNullable < FL [ 'onMomentumScrollEnd' ] > > (
96- ( e ) => {
97- console . log ( prefix , 'onMomentumScrollEnd' , {
98- y : e . nativeEvent . contentOffset . y ,
99- } ) ;
100- } ,
101- [ ]
102- ) ,
103- onContentSizeChange : useCallback < NonNullable < FL [ 'onContentSizeChange' ] > > (
104- ( w , h ) => {
105- console . log ( prefix , 'onContentSizeChange' , { width : w , height : h } ) ;
106- } ,
107- [ ]
108- ) ,
109- onScroll : useCallback < NonNullable < FL [ 'onScroll' ] > > ( ( e ) => {
95+ onMomentumScrollEnd : useCallback < FLFn < 'onMomentumScrollEnd' > > ( ( e ) => {
96+ console . log ( prefix , 'onMomentumScrollEnd' , {
97+ y : e . nativeEvent . contentOffset . y ,
98+ } ) ;
99+ } , [ ] ) ,
100+ onContentSizeChange : useCallback < FLFn < 'onContentSizeChange' > > ( ( w , h ) => {
101+ console . log ( prefix , 'onContentSizeChange' , { width : w , height : h } ) ;
102+ } , [ ] ) ,
103+ onScroll : useCallback < FLFn < 'onScroll' > > ( ( e ) => {
110104 console . log ( prefix , 'onScroll' , {
111105 y : e . nativeEvent . contentOffset . y ,
112106 } ) ;
113107 } , [ ] ) ,
114108 viewabilityConfig,
115109 onViewableItemsChanged,
116- onEndReached : useCallback < NonNullable < FL [ 'onEndReached' ] > > ( ( info ) => {
110+ onEndReached : useCallback < FLFn < 'onEndReached' > > ( ( info ) => {
117111 console . log ( prefix , 'onEndReached' , info ) ;
118112 } , [ ] ) ,
119113 onEndReachedThreshold : 0.25 ,
120- onStartReached : useCallback < NonNullable < FL [ 'onStartReached' ] > > ( ( info ) => {
114+ onStartReached : useCallback < FLFn < 'onStartReached' > > ( ( info ) => {
121115 console . log ( prefix , 'onStartReached' , info ) ;
122116 } , [ ] ) ,
123117 onStartReachedThreshold : 0.25 ,
124- onScrollToIndexFailed : useCallback <
125- NonNullable < FL [ 'onScrollToIndexFailed' ] >
126- > ( ( info ) => {
127- console . log ( prefix , 'onScrollToIndexFailed' , info ) ;
128- } , [ ] ) ,
118+ onScrollToIndexFailed : useCallback < FLFn < 'onScrollToIndexFailed' > > (
119+ ( info ) => {
120+ console . log ( prefix , 'onScrollToIndexFailed' , info ) ;
121+ } ,
122+ [ ]
123+ ) ,
129124 } ;
130125}
131126
0 commit comments