/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from 'react';
import type { LayoutChangeEvent } from 'react-native';
import { StyleSheet, View } from 'react-native';
import Animated from 'react-native-reanimated';
import type { StickyHeaderSharedProps } from './StickyHeaderProps';
import { useStickyHeaderProps } from './useStickyHeaderProps';
// eslint-disable-next-line @typescript-eslint/no-empty-function
const NOOP = () => {};
const createCellRenderer = (itemLayoutAnimation: any) => {
const cellRenderer: React.FC<{ onLayout: (event: LayoutChangeEvent) => void }> = (props) => {
return (
{props.children}
);
};
return cellRenderer;
};
export function withStickyHeader>(component: T) {
const AnimatedComponent = Animated.createAnimatedComponent(component) as any;
return React.forwardRef<
T,
StickyHeaderSharedProps & Animated.AnimateProps>
>((props, ref) => {
const {
containerStyle,
contentContainerStyle,
itemLayoutAnimation,
overScrollMode = 'never',
renderHeader,
renderTabs,
scrollEventThrottle = 16,
style,
...rest
} = props;
const {
contentContainerPaddingTop,
contentContainerPaddingBottom,
headerAnimatedStyle,
headerHeight,
listPaddingTop,
onHeaderLayoutInternal,
onTabsLayoutInternal,
scrollHandler,
tabsHeight,
} = useStickyHeaderProps(props);
const cellRenderer = React.useMemo(
() => createCellRenderer(itemLayoutAnimation),
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);
return (
{renderHeader ? (
{renderHeader()}
) : null}
{renderTabs ? (
{renderTabs()}
) : null}
);
}) as unknown as React.FC<
StickyHeaderSharedProps & Animated.AnimateProps>
>;
}
export const styles = StyleSheet.create({
container: {
alignSelf: 'stretch',
flex: 1,
overflow: 'hidden',
},
header: {
position: 'absolute',
left: 0,
right: 0,
zIndex: 999,
},
});