import React, { memo, useRef, useEffect } from 'react'; import { Svg, Circle } from 'react-native-svg'; import { Animated, Platform, Easing } from 'react-native'; import type { LoadingIconProps } from './type'; const AnimateCircle = Animated.createAnimatedComponent(Circle); const AnimateSvg = Animated.createAnimatedComponent(Svg); const DURATION = 1400; const Circular = ({ color, size }: LoadingIconProps) => { const strokeDash = useRef(new Animated.Value(0)).current; const rotate = useRef(new Animated.Value(0)).current; const startRotation = React.useCallback(() => { Animated.loop( Animated.timing(strokeDash, { toValue: 100, duration: DURATION, // Animated.loop does not work if useNativeDriver is true on web useNativeDriver: Platform.OS !== 'web', easing: Easing.inOut(Easing.ease), }) ).start(); Animated.loop( Animated.timing(rotate, { toValue: 1, duration: DURATION, // Animated.loop does not work if useNativeDriver is true on web useNativeDriver: Platform.OS !== 'web', easing: Easing.linear, }) ).start(); }, []); useEffect(() => { startRotation(); }, []); return ( ); }; export default memo(Circular);