import React, { useEffect } from "react"; import { ScrollView, ScrollViewProps, View, ViewStyle } from "react-native"; import Animated, { useAnimatedStyle, useSharedValue, withTiming, } from "react-native-reanimated"; import { Loader } from "../Loader"; import { Text } from "./Text"; interface HorizontalScrollProps extends ScrollViewProps { data?: T[] | null; renderItem: (item: T, index: number) => React.ReactNode; containerStyle?: ViewStyle; contentContainerStyle?: ViewStyle; loadingContainerStyle?: ViewStyle; height?: number; loading?: boolean; } export function HorizontalScroll({ data = [], renderItem, containerStyle, contentContainerStyle, loadingContainerStyle, loading = false, height = 164, ...props }: HorizontalScrollProps): React.ReactElement { const animatedOpacity = useSharedValue(0); const animatedStyle1 = useAnimatedStyle(() => { return { opacity: withTiming(animatedOpacity.value, { duration: 250 }), }; }); useEffect(() => { if (data) { animatedOpacity.value = 1; } }, [data]); if (data === undefined || data === null || loading) { return ( ); } return ( {data.map((item, index) => ( {renderItem(item, index)} ))} {data.length === 0 && ( No data available )} ); }