import React, { useLayoutEffect, useRef } from 'react'; import { Animated, Easing, Platform, StyleSheet } from 'react-native'; import { StyledSpinnerDot, StyledSpinnerRow } from './StyledSpinner'; const AnimatedRow = Animated.createAnimatedComponent(StyledSpinnerRow); const AnimatedDot = Animated.createAnimatedComponent(StyledSpinnerDot); const AnimatedSpinner = ({ size, intent, }: { size: 'small' | 'medium'; intent: 'primary' | 'inverted'; }) => { const rotateAnimation = useRef(new Animated.Value(0)); useLayoutEffect(() => { const animation = Animated.loop( Animated.timing(rotateAnimation.current, { toValue: 1, duration: 1200, easing: Easing.linear, useNativeDriver: Platform.OS !== 'web', }) ); animation.start(); return () => { animation.stop(); }; }, []); const interpolatedRotateAnimation = rotateAnimation.current.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'], }); const rowProps = { themeSize: size, }; const dotProps = { themeSize: size, themeIntent: intent, }; return ( ); }; export { AnimatedSpinner };