11import React from 'react' ;
22import { View , FlatList , FlatListProps , StyleSheet } from 'react-native' ;
3+ import { useSafeAreaInsets } from 'react-native-safe-area-context' ;
34import Animated , {
45 useAnimatedRef ,
56 useScrollViewOffset ,
67 AnimateProps ,
78} from 'react-native-reanimated' ;
8- import { useSafeAreaInsets } from 'react-native-safe-area-context' ;
9+
910import FadingView from '../containers/FadingView' ;
10- import type { SharedScrollContainerProps } from './types' ;
1111import { useScrollContainerLogic } from './useScrollContainerLogic' ;
12+ import type { SharedScrollContainerProps } from './types' ;
1213
1314type AnimatedFlatListType < ItemT = any > = React . ComponentClass <
1415 AnimateProps < FlatListProps < ItemT > > ,
@@ -21,13 +22,16 @@ type AnimatedFlatListProps<ItemT> = AnimatedFlatListBaseProps<ItemT> & {
2122const AnimatedFlatList : AnimatedFlatListType = Animated . createAnimatedComponent ( FlatList ) ;
2223
2324const AnimatedFlatListWithHeaders = < ItemT extends unknown > ( {
24- data,
25- renderItem,
2625 largeHeaderShown,
2726 containerStyle,
2827 LargeHeaderComponent,
2928 largeHeaderContainerStyle,
3029 HeaderComponent,
30+ onLargeHeaderLayout,
31+ onScrollBeginDrag,
32+ onScrollEndDrag,
33+ onMomentumScrollBegin,
34+ onMomentumScrollEnd,
3135 ignoreLeftSafeArea,
3236 ignoreRightSafeArea,
3337 ...rest
@@ -58,18 +62,31 @@ const AnimatedFlatListWithHeaders = <ItemT extends unknown>({
5862 < AnimatedFlatList
5963 ref = { scrollRef }
6064 scrollEventThrottle = { 16 }
61- overScrollMode = { ' auto' }
65+ overScrollMode = " auto"
6266 automaticallyAdjustContentInsets = { false }
63- onScrollBeginDrag = { debouncedFixScroll . cancel }
64- onScrollEndDrag = { debouncedFixScroll }
65- onMomentumScrollBegin = { debouncedFixScroll . cancel }
66- onMomentumScrollEnd = { debouncedFixScroll }
67- showsVerticalScrollIndicator = { true }
67+ onScrollBeginDrag = { ( e ) => {
68+ debouncedFixScroll . cancel ( ) ;
69+ if ( onScrollBeginDrag ) onScrollBeginDrag ( e ) ;
70+ } }
71+ onScrollEndDrag = { ( e ) => {
72+ debouncedFixScroll ( ) ;
73+ if ( onScrollEndDrag ) onScrollEndDrag ( e ) ;
74+ } }
75+ onMomentumScrollBegin = { ( e ) => {
76+ debouncedFixScroll . cancel ( ) ;
77+ if ( onMomentumScrollBegin ) onMomentumScrollBegin ( e ) ;
78+ } }
79+ onMomentumScrollEnd = { ( e ) => {
80+ debouncedFixScroll ( ) ;
81+ if ( onMomentumScrollEnd ) onMomentumScrollEnd ( e ) ;
82+ } }
6883 ListHeaderComponent = {
6984 LargeHeaderComponent ? (
7085 < View
7186 onLayout = { ( e ) => {
7287 largeHeaderHeight . value = e . nativeEvent . layout . height ;
88+
89+ if ( onLargeHeaderLayout ) onLargeHeaderLayout ( e . nativeEvent . layout ) ;
7390 } }
7491 >
7592 < FadingView opacity = { largeHeaderOpacity } style = { largeHeaderContainerStyle } >
@@ -78,8 +95,6 @@ const AnimatedFlatListWithHeaders = <ItemT extends unknown>({
7895 </ View >
7996 ) : undefined
8097 }
81- data = { data }
82- renderItem = { renderItem }
8398 { ...rest }
8499 />
85100 </ View >
0 commit comments