import { Text, View } from 'react-native'; import Svg, { Circle } from 'react-native-svg'; import Animated, { useAnimatedProps } from 'react-native-reanimated'; import { r, type, useColors, useFontScale, scaleFontMetric, } from '../../../theme'; import { A11Y_HIDDEN_PROPS } from '../shared/a11y'; import { normalizeCircularProgress } from './normalizeCircularProgress'; import { useCircularProgressAnimation } from './useCircularProgressAnimation'; import type { CircularProgressProps } from './types'; import { styles } from './styles'; const AnimatedCircle = Animated.createAnimatedComponent(Circle); export function CircularProgress({ value, animated = false, onAnimationComplete, size = r(32), thickness = r(2), color, trackColor, showLabel = false, formatLabel, labelColor, accessibilityLabel = '进度', style, testID, }: CircularProgressProps): React.JSX.Element { const colors = useColors(); const fontScale = useFontScale(); const normalized = normalizeCircularProgress({ value, size, thickness }); const { circumference, safeValue, percentage, radius, safeSize, safeThickness, } = normalized; const center = safeSize / 2; const { progress, percentage: visualPercentage } = useCircularProgressAnimation( safeValue, animated, showLabel, onAnimationComplete ); const animatedProps = useAnimatedProps(() => ({ strokeDashoffset: circumference * (1 - progress.value), })); return ( {showLabel ? ( {formatLabel ? formatLabel(visualPercentage) : `${visualPercentage}%`} ) : null} ); }