import { FlashList } from "@shopify/flash-list"; import type React from "react"; import { type PropsWithChildren, useCallback, useEffect, useRef, useState, } from "react"; import { Animated, View, type ViewProps } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Text } from "@/components/common/Text"; import { ParallaxScrollView } from "@/components/ParallaxPage"; const ANIMATION_ENTER = 250; const ANIMATION_EXIT = 250; const BACKDROP_DURATION = 5000; type Render = React.ComponentType | React.ReactElement | null | undefined; interface Props { data: T[]; images: string[]; logo?: React.ReactElement; HeaderContent?: () => React.ReactElement; MainContent?: () => React.ReactElement; listHeader: string; renderItem: (item: T, index: number) => Render; keyExtractor: (item: T) => string; onEndReached?: (() => void) | null | undefined; } const ParallaxSlideShow = ({ data, images, logo, HeaderContent, MainContent, listHeader, renderItem, keyExtractor, onEndReached, }: PropsWithChildren & ViewProps>) => { const insets = useSafeAreaInsets(); const [currentIndex, setCurrentIndex] = useState(0); const fadeAnim = useRef(new Animated.Value(0)).current; const enterAnimation = useCallback( () => Animated.timing(fadeAnim, { toValue: 1, duration: ANIMATION_ENTER, useNativeDriver: true, }), [fadeAnim], ); const exitAnimation = useCallback( () => Animated.timing(fadeAnim, { toValue: 0, duration: ANIMATION_EXIT, useNativeDriver: true, }), [fadeAnim], ); useEffect(() => { if (images?.length) { enterAnimation().start(); const intervalId = setInterval(() => { Animated.sequence([enterAnimation(), exitAnimation()]).start(() => { fadeAnim.setValue(0); setCurrentIndex((prevIndex) => (prevIndex + 1) % images?.length); }); }, BACKDROP_DURATION); return () => { clearInterval(intervalId); }; } }, [ fadeAnim, images, enterAnimation, exitAnimation, setCurrentIndex, currentIndex, ]); return ( } logo={logo} > {HeaderContent?.()} {MainContent?.()} No results } contentInsetAdjustmentBehavior='automatic' ListHeaderComponent={ {listHeader} } nestedScrollEnabled showsVerticalScrollIndicator={false} //@ts-ignore renderItem={({ item, index }) => renderItem(item, index)} keyExtractor={keyExtractor} numColumns={3} estimatedItemSize={214} ItemSeparatorComponent={() => } /> ); }; export default ParallaxSlideShow;