import React, { useEffect, useState } from 'react'; import LottieView from 'lottie-react-native'; import { CommonButtonProps } from '../button/Button'; import { isIos } from '../../internal/utils/functions'; import { AccessibilityInfo } from 'react-native'; import SvgSpinnerGap from './svg/SvgSpinnerGap'; import { SemanticColor } from '../../foundation'; type Props = { color: 'teal' | 'white'; /** @deprecated Button pending 상태에서만 사용 가능합니다 */ size?: CommonButtonProps['size']; }; /** * # [Component] Spin * * 화면 중앙 정렬은 부모 컴포넌트에서 해주세요. * * ## Props * * ### `color` * - teal 과 white 중 선택 가능합니다. * * ### `size` * - Button 컴포넌트 사용시, pending 상태에서만 Button icon 사이즈에 맞게 'large' | 'medium' | 'small' | 'tiny' 중 선택 가능합니다. * - Button 컴포넌트가 아닌 경우 32 로 고정됩니다. */ export function Spin(props: Props): React.JSX.Element { const { color, size } = props; const spinSize = (() => { if (size === 'medium' || size === 'small') return 16; if (size === 'tiny') return 14; if (size === 'large') return 20; return 32; // default size })(); const isReducedMotion = useIsReducesMotion(); if (isReducedMotion) { // 동작줄이기 설정된 경우 로띠 대신 정적 이미지로 대체 const staticSpinColor = color === 'white' ? SemanticColor.text_white : SemanticColor.text_purple; return ; } const source = color === 'white' ? require('./lottie/spin_white.json') : require('./lottie/spin_rebrand.json'); return ( ); } function useIsReducesMotion() { const [isReducedMotion, setIsReducedMotion] = useState(false); useEffect(() => { AccessibilityInfo.isReduceMotionEnabled().then(setIsReducedMotion); }, []); return isReducedMotion; }