/* eslint-disable @typescript-eslint/no-explicit-any */ import type { FlashListProps } from '@shopify/flash-list'; import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import Animated from 'react-native-reanimated'; import type { StickyHeaderFlashListProps } from './StickyHeaderProps'; import { useStickyHeaderProps } from './useStickyHeaderProps'; // eslint-disable-next-line @typescript-eslint/no-empty-function const NOOP = () => {}; export function withStickyHeaderFlashList>>( flashListComponent: T ) { const AnimatedFlashList = Animated.createAnimatedComponent(flashListComponent) as any; return React.forwardRef< T, StickyHeaderFlashListProps & Animated.AnimateProps> >((props, ref) => { const { containerStyle, contentContainerStyle, overScrollMode = 'never', onScroll, onScrollEndDrag, onMomentumScrollEnd, onTabsLayout, renderHeader, renderTabs, scrollEventThrottle = 16, ...rest } = props; const { contentContainerPaddingTop, contentContainerPaddingBottom, headerAnimatedStyle, headerHeight, onHeaderLayoutInternal, onTabsLayoutInternal, scrollHandler, tabsHeight, } = useStickyHeaderProps({ contentContainerStyle, sections: [], // is not needed with FlashList onMomentumScrollEnd, onScroll, onScrollEndDrag, onTabsLayout, }); const flattenContentContainerStyle = React.useMemo(() => { return StyleSheet.flatten([ contentContainerStyle, { paddingBottom: tabsHeight + contentContainerPaddingBottom, paddingTop: headerHeight + contentContainerPaddingTop, }, ]); }, [ contentContainerPaddingTop, contentContainerPaddingBottom, contentContainerStyle, headerHeight, tabsHeight, ]); return ( {renderHeader ? ( {renderHeader()} ) : null} {renderTabs ? ( {renderTabs()} ) : null} ); }) as unknown as React.FC< StickyHeaderFlashListProps & Animated.AnimateProps> >; } const styles = StyleSheet.create({ container: { alignSelf: 'stretch', flex: 1, overflow: 'hidden', }, header: { position: 'absolute', left: 0, right: 0, zIndex: 999, }, });