import React, { useEffect, useRef } from 'react'; import { Animated, Easing } from 'react-native'; import { Ux4gCircularProgress, Ux4gCircularProgressProps } from './CircularProgress'; export interface Ux4gAnimatedCircularProgressProps extends Omit { value: number; duration?: number; } const AnimatedProgress = Animated.createAnimatedComponent( class extends React.Component { render() { return ; } } ); export const Ux4gAnimatedCircularProgress: React.FC = ({ value, duration = 700, ...rest }) => { const animatedValue = useRef(new Animated.Value(0)).current; const [currentValue, setCurrentValue] = React.useState(0); useEffect(() => { const listener = animatedValue.addListener(({ value: val }) => { setCurrentValue(val); }); const animation = Animated.timing(animatedValue, { toValue: Math.max(0, Math.min(value, 1)), duration, easing: Easing.inOut(Easing.ease), useNativeDriver: false, }); animation.start(); return () => { animation.stop(); animatedValue.removeListener(listener); }; }, [value, duration]); return ; };