import React, { useEffect, useRef } from 'react'; import { Animated, Easing, StyleSheet, Text, View } from 'react-native'; import Svg, { Circle, Defs, LinearGradient, Stop } from 'react-native-svg'; const AnimatedCircle = Animated.createAnimatedComponent(Circle); export type HealthProgressRingProps = { progress: number; // 0-100 size?: number; strokeWidth?: number; gradientColors?: string[]; label?: string; suffix?: string; title: string; }; export function HealthProgressRing({ progress, size = 80, strokeWidth = 8, gradientColors = ['#5B4CFF', '#9B8AFB'], label, suffix = '%', title, }: HealthProgressRingProps) { const animatedProgress = useRef(new Animated.Value(0)).current; const radius = (size - strokeWidth) / 2; const circumference = 2 * Math.PI * radius; const center = size / 2; useEffect(() => { Animated.timing(animatedProgress, { toValue: progress, duration: 1000, easing: Easing.out(Easing.cubic), useNativeDriver: true, }).start(); }, [progress]); const strokeDashoffset = animatedProgress.interpolate({ inputRange: [0, 100], outputRange: [circumference, 0], extrapolate: 'clamp', }); const gradientId = useRef(`grad-${Math.random().toString(36).substr(2, 9)}`).current; return ( {/* Background Circle */} {/* Progress Circle */} {label ?? progress} {suffix} {title} ); } const styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', }, centerContent: { position: 'absolute', alignItems: 'center', justifyContent: 'center', }, valueContainer: { flexDirection: 'row', alignItems: 'flex-end', }, valueText: { fontSize: 20, fontWeight: 'bold', color: '#1F2937', fontFamily: 'AliBold', lineHeight: 24, }, suffixText: { fontSize: 12, color: '#6B7280', fontWeight: '500', marginLeft: 1, marginBottom: 3, fontFamily: 'AliRegular', }, titleText: { marginTop: 8, fontSize: 14, color: '#4B5563', // gray-600 fontFamily: 'AliRegular', }, });