From a562e45ffdc4bc4226e14e1804f5050c4ae438c0 Mon Sep 17 00:00:00 2001 From: tapframe Date: Wed, 3 Sep 2025 17:17:20 +0530 Subject: [PATCH] perfomance optimziations --- src/components/home/HeroCarousel.tsx | 102 ++++++++++++++++++--------- 1 file changed, 68 insertions(+), 34 deletions(-) diff --git a/src/components/home/HeroCarousel.tsx b/src/components/home/HeroCarousel.tsx index 6585c4ac..41ab4318 100644 --- a/src/components/home/HeroCarousel.tsx +++ b/src/components/home/HeroCarousel.tsx @@ -1,6 +1,6 @@ -import React, { useMemo, useState } from 'react'; +import React, { useMemo, useState, useEffect } from 'react'; import { View, Text, StyleSheet, Dimensions, TouchableOpacity, ViewStyle, TextStyle, ImageStyle, FlatList, StyleProp } from 'react-native'; -import Animated, { FadeIn, FadeOut, Easing } from 'react-native-reanimated'; +import Animated, { FadeIn, FadeOut, Easing, useSharedValue, withTiming, useAnimatedStyle } from 'react-native-reanimated'; import { LinearGradient } from 'expo-linear-gradient'; import { Image as ExpoImage } from 'expo-image'; import { MaterialIcons } from '@expo/vector-icons'; @@ -77,7 +77,12 @@ const HeroCarousel: React.FC = ({ items, loading = false }) = const interval = CARD_WIDTH + 16; const idx = Math.round(offsetX / interval); const clamped = Math.max(0, Math.min(idx, data.length - 1)); - if (clamped !== activeIndex) setActiveIndex(clamped); + if (clamped !== activeIndex) { + // Small delay to ensure smooth transition + setTimeout(() => { + setActiveIndex(clamped); + }, 50); + } }; const handleScroll = (event: any) => { @@ -85,9 +90,62 @@ const HeroCarousel: React.FC = ({ items, loading = false }) = const interval = CARD_WIDTH + 16; const idx = Math.round(offsetX / interval); const clamped = Math.max(0, Math.min(idx, data.length - 1)); - if (clamped !== activeIndex) setActiveIndex(clamped); + if (clamped !== activeIndex) { + setActiveIndex(clamped); + } }; + // Memoized background component with improved timing + const BackgroundImage = React.memo(({ + item, + insets + }: { + item: StreamingContent; + insets: any; + }) => { + const animatedOpacity = useSharedValue(1); + + useEffect(() => { + // Start with opacity 0 and animate to 1 + animatedOpacity.value = 0; + animatedOpacity.value = withTiming(1, { duration: 400 }); + }, [item.id]); + + const animatedStyle = useAnimatedStyle(() => ({ + opacity: animatedOpacity.value, + })); + + return ( + } + pointerEvents="none" + > + + + + + + ); + }); + return ( @@ -113,36 +171,12 @@ const HeroCarousel: React.FC = ({ items, loading = false }) = )} )} - {data[activeIndex] && ( - } - pointerEvents="none" - > - - - - - - )} + {data[activeIndex] && ( + + )} {/* Bottom blend to HomeScreen background (not the card) */}