import { useEffect, useState } from 'react'; import Animated, { useSharedValue, withTiming, useAnimatedStyle, } from 'react-native-reanimated'; import Svg, { Path } from 'react-native-svg'; import type { IHeartSvgProps } from './types'; const AnimatedSvg = Animated.createAnimatedComponent(Svg); export const HeartSvg = ({ filled, fillColor, strokeColor, inactiveFillColor, inactiveStrokeColor, size, duration = 350, }: IHeartSvgProps) => { const progress = useSharedValue(filled ? 1 : 0); const [currentFill, setCurrentFill] = useState( filled ? fillColor : inactiveFillColor ); const [currentStroke, setCurrentStroke] = useState( filled ? strokeColor : inactiveStrokeColor ); const animatedStyle = useAnimatedStyle(() => { return { opacity: 1, }; }); useEffect(() => { progress.value = withTiming(filled ? 1 : 0, { duration, }); const timer = setTimeout(() => { if (filled) { setCurrentFill(fillColor); setCurrentStroke(strokeColor); } else { setCurrentFill(inactiveFillColor); setCurrentStroke(inactiveStrokeColor); } }, duration * 0.1); return () => clearTimeout(timer); }, [ filled, duration, fillColor, strokeColor, inactiveFillColor, inactiveStrokeColor, progress, ]); return ( ); };