스피너 (Spinner)
스피너는 로딩 중임을 나타내는 회전 애니메이션 표시 컴포넌트예요. 크기, 색상, 로딩 상태를 쉽게 제어할 수 있고, 인디케이터 파트를 통해 애니메이션 속도나 커스텀 아이콘까지 자유롭게 바꿀 수 있어요. 이 문서에서는 기본 사용법부터 커스터마이징, API까지 차근차근 살펴볼게요.
출처: 문서
본문
Import
import { Spinner } from 'heroui-native';
Anatomy
<Spinner>
<Spinner.Indicator>...</Spinner.Indicator>
</Spinner>
- Spinner: 로딩 상태, 크기, 색상을 제어하는 메인 컨테이너예요. 자식을 제공하지 않으면 기본 애니메이션 인디케이터를 렌더링해요.
- Spinner.Indicator: 애니메이션 구성과 아이콘 모양을 커스터마이징하는 선택적 하위 컴포넌트예요. 기본 아이콘을 대체할 사용자 정의 children을 받을 수 있어요.
Usage
Basic Usage
Spinner 컴포넌트는 회전하는 로딩 인디케이터를 표시해요.
<Spinner />
Sizes
size prop으로 스피너 크기를 제어해요.
<Spinner size="sm" />
<Spinner size="md" />
<Spinner size="lg" />
Colors
미리 정의된 색상 변형이나 사용자 정의 색상을 사용할 수 있어요.
<Spinner color="default" />
<Spinner color="success" />
<Spinner color="warning" />
<Spinner color="danger" />
<Spinner color="#8B5CF6" />
Loading State
isLoading prop으로 스피너 표시 여부를 제어해요.
<Spinner isLoading={true} />
<Spinner isLoading={false} />
Animation Speed
Indicator 컴포넌트의 animation prop을 사용해 회전 속도를 커스터마이즈할 수 있어요.
<Spinner>
<Spinner.Indicator animation={{ rotation: { speed: 0.5 } }} />
</Spinner>
<Spinner>
<Spinner.Indicator animation={{ rotation: { speed: 2 } }} />
</Spinner>
Custom Icon
기본 스피너 아이콘을 사용자 정의 콘텐츠로 대체할 수 있어요.
const themeColorForeground = useThemeColor('foreground')
<Spinner>
<Spinner.Indicator>
<Ionicons name="refresh" size={24} color={themeColorForeground} />
</Spinner.Indicator>
</Spinner>
<Spinner>
<Spinner.Indicator>
<Text>⏳</Text>
</Spinner.Indicator>
</Spinner>
Example
import { Spinner } from 'heroui-native';
import { Ionicons } from '@expo/vector-icons';
import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
export default function SpinnerExample() {
const [isLoading, setIsLoading] = React.useState(true);
return (
<View className="gap-4 p-4 bg-background">
<View className="flex-row items-center gap-2 p-4 rounded-lg bg-stone-200">
<Spinner size="sm" color="default" />
<Text className="text-stone-500">Loading content...</Text>
</View>
<View className="items-center p-8 rounded-2xl bg-stone-200">
<Spinner size="lg" color="success" isLoading={isLoading} />
<Text className="text-stone-500 mt-4">Processing...</Text>
<TouchableOpacity onPress={() => setIsLoading(!isLoading)}>
<Text className="text-primary mt-2 text-sm">
{isLoading ? 'Tap to stop' : 'Tap to start'}
</Text>
</TouchableOpacity>
</View>
<View className="flex-row gap-4 items-center justify-center">
<Spinner size="md" color="#EC4899">
<Spinner.Indicator animation={{ rotation: { speed: 0.7 } }}>
<Ionicons name="refresh" size={24} color="#EC4899" />
</Spinner.Indicator>
</Spinner>
</View>
</View>
);
}
더 많은 예시는 GitHub 저장소에서 찾아볼 수 있어요.
API Reference
Spinner
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
undefined |
스피너 안에 렌더링할 콘텐츠 |
size |
'sm' | 'md' | 'lg' |
'md' |
스피너의 크기 |
color |
'default' | 'success' | 'warning' | 'danger' | string |
'default' |
스피너의 색상 테마 |
isLoading |
boolean |
true |
스피너가 로딩 중인지 여부 |
className |
string |
undefined |
스피너의 사용자 정의 클래스 이름 |
animation |
SpinnerRootAnimation |
- | 애니메이션 구성 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View prop 지원 |
SpinnerRootAnimation
Spinner 컴포넌트의 애니메이션 구성이에요. 다음을 사용할 수 있어요.
false또는"disabled": 루트 애니메이션만 비활성화"disable-all": 자식을 포함한 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용object: 사용자 정의 애니메이션 구성
| prop | type | default | description |
|---|---|---|---|
state |
'disabled' | 'disable-all' | boolean |
- | 속성을 커스터마이즈하는 동안 애니메이션 비활성화 |
entering.value |
EntryOrExitLayoutType |
FadeIn.duration(200).easing(Easing.out(Easing.ease)) |
사용자 정의 진입 애니메이션 |
exiting.value |
EntryOrExitLayoutType |
FadeOut.duration(100) |
사용자 정의 퇴장 애니메이션 |
Spinner.Indicator
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
undefined |
인디케이터 안에 렌더링할 콘텐츠 |
iconProps |
SpinnerIconProps |
undefined |
기본 아이콘의 props |
className |
string |
undefined |
인디케이터 요소의 사용자 정의 클래스 이름 |
animation |
SpinnerIndicatorAnimation |
- | 애니메이션 구성 |
isAnimatedStyleActive |
boolean |
true |
애니메이션 스타일(react-native-reanimated) 활성 여부 |
...Animated.ViewProps |
Animated.ViewProps |
- | 모든 Reanimated Animated.View prop 지원 |
SpinnerIndicatorAnimation
Spinner.Indicator 컴포넌트의 애니메이션 구성이에요. 다음을 사용할 수 있어요.
false또는"disabled": 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용object: 사용자 정의 애니메이션 구성
| prop | type | default | description |
|---|---|---|---|
state |
'disabled' | boolean |
- | 속성을 커스터마이즈하는 동안 애니메이션 비활성화 |
rotation.speed |
number |
1.1 |
회전 속도 배수 |
rotation.easing |
WithTimingConfig['easing'] |
Easing.linear |
애니메이션 이징 구성 |
SpinnerIconProps
| prop | type | default | description |
|---|---|---|---|
width |
number | string |
24 |
아이콘의 너비 |
height |
number | string |
24 |
아이콘의 높이 |
color |
string |
'currentColor' |
아이콘의 색상 |