import React, { useRef, useEffect } from 'react'; import { View, Animated, Text, StyleSheet } from 'react-native'; import { useTheme } from '../../theme/useTheme'; import type { SpinnerProps, SpinnerSize } from './Spinner.types'; const sizeMap: Record = { sm: 20, md: 32, lg: 48, }; export const Spinner: React.FC = ({ size = 'md', color = 'primary', label, style, }) => { const theme = useTheme(); const spinValue = useRef(new Animated.Value(0)).current; const colorValue = theme.colors[color]; const dimension = sizeMap[size]; useEffect(() => { const animation = Animated.loop( Animated.timing(spinValue, { toValue: 1, duration: 800, useNativeDriver: true, }) ); animation.start(); return () => animation.stop(); }, [spinValue]); const rotation = spinValue.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'], }); return ( {label && ( {label} )} ); }; const styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', }, spinner: {}, label: { textAlign: 'center', }, });