import { useEffect } from 'react'; import { StyleSheet, View } from 'react-native'; import Animated, { useAnimatedProps, useSharedValue, withTiming } from 'react-native-reanimated'; import Svg, { Circle, G, Text as SvgText } from 'react-native-svg'; type GaugeArcProps = { value: number; max: number; label: string; unit: string; color: string; size?: number; }; const AnimatedCircle = Animated.createAnimatedComponent(Circle); export const GaugeArc = ({ value, max, label, unit, color, size = 140 }: GaugeArcProps) => { const radius = (size - 20) / 2; const circumference = 2 * Math.PI * radius; const arcLength = circumference * 0.75; const strokeWidth = 12; const progress = useSharedValue(0); const normalized = Math.max(0, Math.min(max > 0 ? value / max : 0, 1)); const displayText = `${value.toFixed(1)} ${unit}`; useEffect(() => { progress.value = withTiming(normalized, { duration: 600 }); }, [normalized, progress]); const animatedStroke = useAnimatedProps(() => { const dashOffset = arcLength - arcLength * progress.value; return { strokeDashoffset: dashOffset, }; }); return ( {displayText} {label} ); }; const styles = StyleSheet.create({ wrapper: { alignItems: 'center', justifyContent: 'center', }, });