import React from 'react' import { FlatList, FlatListProps, useWindowDimensions, View, StyleSheet } from 'react-native' import colors from '@app/styles/colors' import GradientBackground, { GradientBackgroundProps } from '@app/components/GradientBackground' import { useLayout } from '@react-native-community/hooks' import NothingHere from './NothingHere' import ImageGradientBackground, { ImageGradientBackgroundProps } from './ImageGradientBackground' export type BackgroundHeaderFlatListPropsBase = FlatListProps & { contentMarginTop?: number } export type BackgroundHeaderFlatListProp = BackgroundHeaderFlatListPropsBase & { BackgroundComponent: typeof ImageGradientBackground | typeof GradientBackground backgroundProps?: ImageGradientBackgroundProps | GradientBackgroundProps } function BackgroundHeaderFlatList(props: BackgroundHeaderFlatListProp) { const window = useWindowDimensions() const headerLayout = useLayout() let marginBottom = -window.height + (props.contentMarginTop || 0) if (props.ListHeaderComponent) { marginBottom += headerLayout.height || window.height } const headerStyle = { marginBottom } return ( {props.ListHeaderComponent} } ListHeaderComponentStyle={[headerStyle]} ListEmptyComponent={props.ListEmptyComponent || } /> ) } const styles = StyleSheet.create({ list: { backgroundColor: colors.gradient.low, }, nothing: { width: '100%', }, }) export default BackgroundHeaderFlatList