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 GradientImageBackground, { GradientImageBackgroundProps } from './GradientImageBackground' export type GradientBackgroundHeaderFlatListPropsBase = FlatListProps & { contentMarginTop?: number } export type GradientBackgroundHeaderFlatListProp = GradientBackgroundHeaderFlatListPropsBase & { BackgroundComponent: typeof GradientImageBackground | typeof GradientBackground backgroundProps?: GradientImageBackgroundProps | GradientBackgroundProps } function GradientBackgroundHeaderFlatList(props: GradientBackgroundHeaderFlatListProp) { 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 GradientBackgroundHeaderFlatList