Ver3.0 ๐จ ๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ ์ ๋๋ฉ์ด์ ๊ตฌํ: Animated API๋ก ์ฑ์ ์๋ช ๋ถ์ด๋ฃ๊ธฐ

๐จ ๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ ์ ๋๋ฉ์ด์ ๊ตฌํ: Animated API๋ก ์ฑ์ ์๋ช ๋ถ์ด๋ฃ๊ธฐ
๐ ์ ์ ๋๋ฉ์ด์ ์ด ์ค์ํ ๊น?
์ผ, ์์งํ ๋งํด์ ์์ฆ ์ฑ๋ค ๋ณด๋ฉด ๋ค๋ค ์์ฒญ ๋ถ๋๋ฝ๊ฒ ์์ง์ด์์? ๐
๋ฒํผ ๋๋ฅด๋ฉด ์ด์ง ๋๋ฆฌ๋ ๋๋, ํ๋ฉด ์ ํํ ๋ ์ค์ฝ ๋์ด๊ฐ๋ ๋๋...
์ด๋ฐ ๊ฒ ๋ค ์ ๋๋ฉ์ด์
์ด์ผ!
๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ๋ก ์ฑ ๋ง๋ค ๋๋ ๋ง์ฐฌ๊ฐ์ง์ผ.
๊ทธ๋ฅ ๋ฑ๋ฑํ๊ฒ ํ๋ฉด๋ง ๋ฐ๋๋ฉด ๋ญ๊ฐ 2000๋
๋ ์ฑ ์ฐ๋ ๋๋์ด์์? ๐ค
์ฌ์ฉ์๋ค์ ์ด์ ๋ถ๋๋ฌ์ด ์ ํ, ์์ฐ์ค๋ฌ์ด ์์ง์์ ๋น์ฐํ๊ฒ ์๊ฐํด.
๊ทธ๋์ ์ค๋์ ๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ์ Animated API๋ฅผ ์์ ์ ๋ณตํด๋ณผ ๊ฑฐ์ผ!
์ฒ์ ๋ณด๋ฉด ์ข ์ด๋ ค์ ๋ณด์ผ ์ ์๋๋ฐ, ์น๊ตฌํํ
์ค๋ช
ํ๋ฏ์ด ์ฝ๊ฒ ํ์ด์ ์๋ ค์ค๊ฒ! ๐ช
- โ Animated API์ ๊ธฐ๋ณธ ๊ฐ๋ ๊ณผ ์๋ ์๋ฆฌ
- โ ๋ค์ํ ์ ๋๋ฉ์ด์ ํ์ (Timing, Spring, Decay)
- โ ์ค์ ์์ ๋ก ๋ฐฐ์ฐ๋ ์ ๋๋ฉ์ด์ ๊ตฌํ
- โ ์ฑ๋ฅ ์ต์ ํ ํ๊ณผ ์ฃผ์์ฌํญ
- โ ๊ณ ๊ธ ํ ํฌ๋๊ณผ ์กฐํฉ ํ์ฉ๋ฒ
๐ฏ Animated API๋ ๋ฌด์์ธ๊ฐ?
๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ์ Animated API๋ ๋ง ๊ทธ๋๋ก ์ ๋๋ฉ์ด์
์ ๋ง๋ค๊ธฐ ์ํ ๋๊ตฌ์ผ! ๐ ๏ธ
๊ทผ๋ฐ ์ด๊ฒ ๊ทธ๋ฅ ๋จ์ํ ๋๊ตฌ๊ฐ ์๋๋ผ, ์์ฒญ ๊ฐ๋ ฅํ๋ฉด์๋ ์ฑ๋ฅ์ด ์ข์ ์น๊ตฌ์ง.
์ผ๋ฐ์ ์ผ๋ก ์๋ฐ์คํฌ๋ฆฝํธ๋ก ์ ๋๋ฉ์ด์
์ ๋ง๋ค๋ฉด ์ด๋ป๊ฒ ๋ ๊น?
๋งค ํ๋ ์๋ง๋ค ์ํ๋ฅผ ์
๋ฐ์ดํธํ๊ณ , ๋ฆฌ๋ ๋๋งํ๊ณ ... ์ด๋ฌ๋ฉด ์ฑ๋ฅ์ด ๋จ์ด์ ธ. ๐ฐ
ํนํ ๋ชจ๋ฐ์ผ์์๋ 60fps๋ฅผ ์ ์งํ๊ธฐ๊ฐ ์ ๋ง ์ด๋ ค์.
ํ์ง๋ง Animated API๋ ๋ค๋ฅด๊ฒ ์๋ํด!
๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ๋ฅผ ์ฌ์ฉํ๋ฉด ์๋ฐ์คํฌ๋ฆฝํธ ์ค๋ ๋๋ฅผ ๊ฑฐ์น์ง ์๊ณ
์ง์ ๋ค์ดํฐ๋ธ ๋ ์ด์ด์์ ์ ๋๋ฉ์ด์
์ ์ฒ๋ฆฌํ ์ ์๊ฑฐ๋ . ๐
๊ทธ๋์ ์์ฒญ ๋ถ๋๋ฝ๊ณ ๋น ๋ฅธ ์ ๋๋ฉ์ด์
์ ๋ง๋ค ์ ์์ด!
์ด๊ฑธ ํ์ฑํํ๋ฉด ์๋ฐ์คํฌ๋ฆฝํธ ๋ธ๋ฆฟ์ง๋ฅผ ๊ฑฐ์น์ง ์๊ณ ๋ค์ดํฐ๋ธ ๋ ๋ฒจ์์ ์ ๋๋ฉ์ด์ ์ด ์คํ๋ผ์
60fps๋ฅผ ์์ ์ ์ผ๋ก ์ ์งํ ์ ์์ด. ์ง์ง ๊ฒ์ ์ฒด์ธ์ ์ผ! ๐ฎ
๐ฆ Animated API์ ํต์ฌ ๊ตฌ์ฑ ์์
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก Animated API์ ๊ตฌ์กฐ๋ฅผ ํํค์ณ๋ณด์! ๐
ํฌ๊ฒ ์ธ ๊ฐ์ง ํต์ฌ ์์๋ก ๋๋ ์ ์์ด.
1๏ธโฃ Animated Values (์ ๋๋ฉ์ด์ ๊ฐ)
์ ๋๋ฉ์ด์
์ ์์์ ์ด์ผ!
๋ณํํ ๊ฐ์ ๋ด๋ ํน๋ณํ ์ปจํ
์ด๋๋ผ๊ณ ์๊ฐํ๋ฉด ๋ผ. ๐
์ฃผ๋ก ๋ ๊ฐ์ง ํ์
์ ์ฌ์ฉํด:
๋จ์ผ ์ซ์ ๊ฐ์ ๋ค๋ฃฐ ๋ ์ฌ์ฉํด. ํฌ๋ช ๋, ์์น, ํฌ๊ธฐ ๊ฐ์ ๊ฑฐ!
const fadeAnim = new Animated.Value(0); // 0๋ถํฐ ์์
const scaleAnim = new Animated.Value(1); // 1๋ถํฐ ์์
๐น Animated.ValueXY
X, Y ์ขํ์ฒ๋ผ ๋ ๊ฐ์ ๊ฐ์ ํจ๊ป ๋ค๋ฃฐ ๋ ์ฌ์ฉํด!
const position = new Animated.ValueXY({ x: 0, y: 0 });
2๏ธโฃ Animated Components (์ ๋๋ฉ์ด์ ์ปดํฌ๋ํธ)
์ผ๋ฐ ์ปดํฌ๋ํธ๋ ์ ๋๋ฉ์ด์
๊ฐ์ ์ง์ ๋ฐ์ ์ ์์ด. ๐
๊ทธ๋์ Animated API๊ฐ ์ ๊ณตํ๋ ํน๋ณํ ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํด์ผ ํด!
| ์ปดํฌ๋ํธ | ์ค๋ช | ์ฃผ์ ์ฉ๋ |
|---|---|---|
| Animated.View | ์ ๋๋ฉ์ด์ ๊ฐ๋ฅํ View | ๋ ์ด์์, ์์น, ํฌ๊ธฐ ๋ณ๊ฒฝ |
| Animated.Text | ์ ๋๋ฉ์ด์ ๊ฐ๋ฅํ Text | ํ ์คํธ ํ์ด๋, ์์ ๋ณ๊ฒฝ |
| Animated.Image | ์ ๋๋ฉ์ด์ ๊ฐ๋ฅํ Image | ์ด๋ฏธ์ง ์ ํ, ํ๋/์ถ์ |
| Animated.ScrollView | ์ ๋๋ฉ์ด์ ๊ฐ๋ฅํ ScrollView | ์คํฌ๋กค ๊ธฐ๋ฐ ์ ๋๋ฉ์ด์ |
์ปค์คํ
์ปดํฌ๋ํธ๋ฅผ ์ ๋๋ฉ์ด์
๊ฐ๋ฅํ๊ฒ ๋ง๋ค๊ณ ์ถ๋ค๋ฉด?
Animated.createAnimatedComponent()๋ฅผ ์ฌ์ฉํ๋ฉด ๋ผ! ๐จ
const AnimatedTouchable = Animated.createAnimatedComponent(TouchableOpacity);
3๏ธโฃ Animation Types (์ ๋๋ฉ์ด์ ํ์ )
๊ฐ์ ์ด๋ป๊ฒ ๋ณํ์ํฌ์ง ์ ํ๋ ๊ฑฐ์ผ!
๊ฐ๊ฐ ํน์ง์ด ๋ค๋ฅด๋๊น ์ํฉ์ ๋ง๊ฒ ๊ณจ๋ผ ์ฐ๋ฉด ๋ผ. ๐ฏ
์๊ฐ์ ๋ฐ๋ผ ์ ํ์ ์ผ๋ก ๊ฐ์ ๋ณํ์์ผ.
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ด๊ณ ๋ง์ด ์ฐ๋ ๋ฐฉ์์ด์ผ!
Animated.timing(fadeAnim, {
toValue: 1, // ๋ชฉํ๊ฐ
duration: 1000, // 1์ด ๋์
useNativeDriver: true // ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ์ฌ์ฉ!
}).start();
๐ Animated.spring
๋ฌผ๋ฆฌ ๋ฒ์น์ ์ ์ฉํ ์คํ๋ง ํจ๊ณผ!
ํตํต ํ๋ ๋๋์ ์ค ์ ์์ด์ ์์ฐ์ค๋ฌ์. ๐ช
Animated.spring(scaleAnim, {
toValue: 1.2,
friction: 3, // ๋ง์ฐฐ๋ ฅ (๋ฎ์์๋ก ๋ ํ)
tension: 40, // ์ฅ๋ ฅ (๋์์๋ก ๋น ๋ฆ)
useNativeDriver: true
}).start();
๐ข Animated.decay
๊ฐ์ ํจ๊ณผ! ์คํฌ๋กค์ด ์ ์ ๋๋ ค์ง๋ ๊ฒ์ฒ๋ผ.
์ฃผ๋ก ์ ์ค์ฒ์ ํจ๊ป ์ฌ์ฉํด.
Animated.decay(position, {
velocity: { x: gestureState.vx, y: gestureState.vy },
deceleration: 0.997, // ๊ฐ์๋ฅ
useNativeDriver: true
}).start();
๐ฌ ์ค์ ์์ : ํ์ด๋ ์ธ ์ ๋๋ฉ์ด์
์ด๋ก ๋ง ๋ณด๋ฉด ์ฌ๋ฏธ์์์? ๐ด
์ค์ ๋ก ์ฝ๋๋ฅผ ์ง๋ฉด์ ๋ฐฐ์๋ณด์!
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํ์ด๋ ์ธ ํจ๊ณผ๋ถํฐ ์์ํ ๊ฒ.
๐จ ๊ธฐ๋ณธ ํ์ด๋ ์ธ ๊ตฌํ
import React, { useEffect, useRef } from 'react';
import { Animated, View, Text, StyleSheet } from 'react-native';
const FadeInView = ({ children }) => {
// 1. Animated.Value ์์ฑ (์ด๊ธฐ๊ฐ 0 = ํฌ๋ช
)
const fadeAnim = useRef(new Animated.Value(0)).current;
useEffect(() => {
// 2. ์ปดํฌ๋ํธ ๋ง์ดํธ ์ ์ ๋๋ฉ์ด์
์์
Animated.timing(fadeAnim, {
toValue: 1, // ์์ ๋ถํฌ๋ช
duration: 2000, // 2์ด ๋์
useNativeDriver: true // ์ฑ๋ฅ ์ต์ ํ!
}).start();
}, [fadeAnim]);
return (
// 3. Animated.View์ opacity ์ ์ฉ
<Animated.View style={{ opacity: fadeAnim }}>
{children}
</Animated.View>
);
};
// ์ฌ์ฉ ์์
const App = () => {
return (
<View style={styles.container}>
<FadeInView>
<Text style={styles.text}>์๋
! ๋ ์์ํ ๋ํ๋ฌ์ง? ๐</Text>
</FadeInView>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f0f0f0'
},
text: {
fontSize: 20,
fontWeight: 'bold'
}
});
export default App;
๋ฆฌ๋ ๋๋ง ์์๋ ๊ฐ์ ์ธ์คํด์ค๋ฅผ ์ ์งํ๊ธฐ ์ํด์์ผ!
2. useNativeDriver: true๋ ํ์!
์ด๊ฒ ์์ด์ผ ๋ค์ดํฐ๋ธ ๋ ๋ฒจ์์ ์ ๋๋ฉ์ด์ ์ด ์คํ๋ผ.
๋จ, transform๊ณผ opacity๋ง ์ง์ํ๋ค๋ ์ ๊ธฐ์ตํด! ๐ฏ
3. .start()๋ฅผ ํธ์ถํด์ผ ์ ๋๋ฉ์ด์ ์ด ์์๋ผ.
์ฝ๋ฐฑ ํจ์๋ฅผ ๋ฃ์ผ๋ฉด ์๋ฃ ์์ ์ ์ ์ ์์ด!
๐ ์ ๋๋ฉ์ด์ ๋ฐ๋ณตํ๊ธฐ
ํ ๋ฒ๋ง ์คํํ๋ ๊ฒ ์๋๋ผ ๊ณ์ ๋ฐ๋ณตํ๊ณ ์ถ๋ค๋ฉด?
Animated.loop()๋ฅผ ์ฌ์ฉํ๋ฉด ๋ผ! ๐
const PulseAnimation = () => {
const pulseAnim = useRef(new Animated.Value(1)).current;
useEffect(() => {
// ๋ฌดํ ๋ฐ๋ณต ์ ๋๋ฉ์ด์
Animated.loop(
Animated.sequence([
Animated.timing(pulseAnim, {
toValue: 1.2,
duration: 500,
useNativeDriver: true
}),
Animated.timing(pulseAnim, {
toValue: 1,
duration: 500,
useNativeDriver: true
})
])
).start();
}, []);
return (
<Animated.View
style={{
transform: [{ scale: pulseAnim }]
}}
>
<Text style={{ fontSize: 50 }}>๐</Text>
</Animated.View>
);
};
์ด๋ ๊ฒ ํ๋ฉด ํํธ๊ฐ ๊ณ์ ๋๊ทผ๋๊ทผ ๋ฐ๋ ํจ๊ณผ๋ฅผ ๋ง๋ค ์ ์์ด! ๐
Animated.sequence()๋ ์ ๋๋ฉ์ด์
์ ์์ฐจ์ ์ผ๋ก ์คํํ๋ ๊ฑฐ๊ณ ,
Animated.loop()๋ก ๊ฐ์ธ๋ฉด ๋ฌดํ ๋ฐ๋ณต์ด์ผ!
๐ช ๊ณ ๊ธ ์ ๋๋ฉ์ด์ ํ ํฌ๋
๊ธฐ๋ณธ์ ๋ง์คํฐํ์ง?
์ด์ ์ข ๋ ๋ฉ์ง ํจ๊ณผ๋ค์ ๋ง๋ค์ด๋ณด์! ๐
๐ฏ ์ฌ๋ฌ ์ ๋๋ฉ์ด์ ์กฐํฉํ๊ธฐ
์ค์ ์ฑ์์๋ ์ฌ๋ฌ ์ ๋๋ฉ์ด์
์ ๋์์ ๋๋ ์์ฐจ์ ์ผ๋ก ์คํํด์ผ ํ ๋๊ฐ ๋ง์.
Animated API๋ ์ด๋ฐ ์กฐํฉ์ ์ํ ๊ฐ๋ ฅํ ๋๊ตฌ๋ค์ ์ ๊ณตํด! ๐ ๏ธ
์ฌ๋ฌ ์ ๋๋ฉ์ด์ ์ ๋์์ ์คํ!
Animated.parallel([
Animated.timing(fadeAnim, {
toValue: 1,
duration: 1000,
useNativeDriver: true
}),
Animated.timing(slideAnim, {
toValue: 0,
duration: 1000,
useNativeDriver: true
})
]).start();
๐น Animated.sequence()
์ ๋๋ฉ์ด์ ์ ์์ฐจ์ ์ผ๋ก ์คํ!
Animated.sequence([
Animated.timing(scaleAnim, {
toValue: 1.2,
duration: 300,
useNativeDriver: true
}),
Animated.timing(scaleAnim, {
toValue: 1,
duration: 300,
useNativeDriver: true
})
]).start();
๐น Animated.stagger()
๊ฐ ์ ๋๋ฉ์ด์ ์ฌ์ด์ ๋๋ ์ด๋ฅผ ์ค์ ์์ฐจ ์คํ!
Animated.stagger(100, [
Animated.timing(anim1, { ... }),
Animated.timing(anim2, { ... }),
Animated.timing(anim3, { ... })
]).start();
๐จ ์ค์ ์์ : ์นด๋ ๋ค์ง๊ธฐ ์ ๋๋ฉ์ด์
์ด์ ์ง์ง ๋ฉ์ง ๊ฑธ ๋ง๋ค์ด๋ณผ๊น?
์นด๋๊ฐ ๋ค์งํ๋ 3D ํจ๊ณผ๋ฅผ ๊ตฌํํด๋ณด์! ๐
import React, { useRef, useState } from 'react';
import { Animated, TouchableOpacity, StyleSheet, Text } from 'react-native';
const FlipCard = () => {
const [isFlipped, setIsFlipped] = useState(false);
const flipAnim = useRef(new Animated.Value(0)).current;
const flipCard = () => {
// ํ์ฌ ์ํ์ ๋ฐ๋ผ ๋ชฉํ๊ฐ ์ค์
const toValue = isFlipped ? 0 : 1;
Animated.spring(flipAnim, {
toValue,
friction: 8,
tension: 10,
useNativeDriver: true
}).start();
setIsFlipped(!isFlipped);
};
// ์๋ฉด ํ์ ๊ฐ๋ (0deg โ 90deg)
const frontInterpolate = flipAnim.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '180deg']
});
// ๋ท๋ฉด ํ์ ๊ฐ๋ (90deg โ 180deg)
const backInterpolate = flipAnim.interpolate({
inputRange: [0, 1],
outputRange: ['180deg', '360deg']
});
// ์๋ฉด ํฌ๋ช
๋
const frontOpacity = flipAnim.interpolate({
inputRange: [0, 0.5, 0.5, 1],
outputRange: [1, 1, 0, 0]
});
// ๋ท๋ฉด ํฌ๋ช
๋
const backOpacity = flipAnim.interpolate({
inputRange: [0, 0.5, 0.5, 1],
outputRange: [0, 0, 1, 1]
});
return (
<TouchableOpacity onPress={flipCard} style={styles.container}>
{/* ์๋ฉด */}
<Animated.View
style={[
styles.card,
styles.cardFront,
{
opacity: frontOpacity,
transform: [{ rotateY: frontInterpolate }]
}
]}
>
<Text style={styles.cardText}>์๋ฉด ๐ด</Text>
</Animated.View>
{/* ๋ท๋ฉด */}
<Animated.View
style={[
styles.card,
styles.cardBack,
{
opacity: backOpacity,
transform: [{ rotateY: backInterpolate }]
}
]}
>
<Text style={styles.cardText}>๋ท๋ฉด ๐ญ</Text>
</Animated.View>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
container: {
width: 200,
height: 300,
alignItems: 'center',
justifyContent: 'center'
},
card: {
width: 200,
height: 300,
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
backfaceVisibility: 'hidden',
borderRadius: 20,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.3,
shadowRadius: 4,
elevation: 5
},
cardFront: {
backgroundColor: '#667eea'
},
cardBack: {
backgroundColor: '#764ba2'
},
cardText: {
fontSize: 24,
color: 'white',
fontWeight: 'bold'
}
});
export default FlipCard;
ํ๋์ Animated.Value๋ฅผ ์ฌ๋ฌ ๊ฐ์ง ๊ฐ์ผ๋ก ๋ณํํ ์ ์๊ฑฐ๋ .
์๋ฅผ ๋ค์ด 0~1 ์ฌ์ด์ ๊ฐ์:
โข ๊ฐ๋๋ก ๋ณํ (0deg โ 180deg)
โข ์์์ผ๋ก ๋ณํ (rgb(0,0,0) โ rgb(255,255,255))
โข ํฌ๊ธฐ๋ก ๋ณํ (100 โ 200)
์ด๋ ๊ฒ ํ๋์ ์ ๋๋ฉ์ด์ ๊ฐ์ผ๋ก ์ฌ๋ฌ ์์ฑ์ ๋์์ ์ ์ดํ ์ ์์ด! ๐ฏ
๐ฑ ์ ์ค์ฒ ๊ธฐ๋ฐ ์ ๋๋ฉ์ด์
์ฌ์ฉ์์ ํฐ์น๋ ๋๋๊ทธ์ ๋ฐ์ํ๋ ์ ๋๋ฉ์ด์
๋ ๋ง๋ค ์ ์์ด!
PanResponder์ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ง์ง ์ธํฐ๋ํฐ๋ธํ UI๋ฅผ ๋ง๋ค ์ ์์ง. ๐
import React, { useRef } from 'react';
import { Animated, PanResponder, View, StyleSheet } from 'react-native';
const DraggableBox = () => {
const pan = useRef(new Animated.ValueXY()).current;
const panResponder = useRef(
PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: Animated.event(
[
null,
{ dx: pan.x, dy: pan.y }
],
{ useNativeDriver: false } // ValueXY๋ ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ๋ฏธ์ง์
),
onPanResponderRelease: () => {
// ๋์ผ๋ฉด ์๋ ์์น๋ก ๋์๊ฐ๊ธฐ
Animated.spring(pan, {
toValue: { x: 0, y: 0 },
useNativeDriver: false
}).start();
}
})
).current;
return (
<View style={styles.container}>
<Animated.View
style={[
styles.box,
{
transform: [
{ translateX: pan.x },
{ translateY: pan.y }
]
}
]}
{...panResponder.panHandlers}
>
<Text style={styles.text}>๋๋๊ทธํด๋ด! ๐ฏ</Text>
</Animated.View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
box: {
width: 150,
height: 150,
backgroundColor: '#667eea',
borderRadius: 20,
justifyContent: 'center',
alignItems: 'center'
},
text: {
color: 'white',
fontSize: 18,
fontWeight: 'bold'
}
});
๊ทธ๋์ useNativeDriver: false๋ก ์ค์ ํด์ผ ํด.
๋์ ์ฑ๋ฅ์ด ์กฐ๊ธ ๋จ์ด์ง ์ ์์ผ๋, ๋ณต์กํ ์ ๋๋ฉ์ด์ ์๋ ์ฃผ์๊ฐ ํ์ํด. ๐ค
โก ์ฑ๋ฅ ์ต์ ํ ๊ฟํ
์ ๋๋ฉ์ด์
์ ๋ฉ์ง์ง๋ง, ์๋ชป ์ฌ์ฉํ๋ฉด ์ฑ์ด ๋ฒ๋ฒ
๊ฑฐ๋ฆด ์ ์์ด. ๐ฐ
์ฑ๋ฅ์ ์ต๋ํ ๋์ด์ฌ๋ฆฌ๋ ๋ฐฉ๋ฒ๋ค์ ์๋ ค์ค๊ฒ!
1๏ธโฃ ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ํ์ฉ
// transform๊ณผ opacity๋ ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ์ฌ์ฉ ๊ฐ๋ฅ!
Animated.timing(animValue, {
toValue: 1,
duration: 300,
useNativeDriver: true // ๐
}).start();
โ ๋์ ์์
// width, height, margin ๋ฑ์ ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ๋ฏธ์ง์
Animated.timing(animValue, {
toValue: 100,
duration: 300,
useNativeDriver: true // ์๋ฌ ๋ฐ์! ๐ฅ
}).start();
๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ๊ฐ ์ง์ํ๋ ์์ฑ๋ค:
โข opacity (ํฌ๋ช
๋)
โข transform (translateX, translateY, scale, rotate ๋ฑ)
์ง์ํ์ง ์๋ ์์ฑ๋ค:
โข width, height
โข margin, padding
โข backgroundColor
โข left, right, top, bottom
2๏ธโฃ ๋ถํ์ํ ๋ฆฌ๋ ๋๋ง ๋ฐฉ์ง
// โ ๋์ ์์: ๋งค๋ฒ ์๋ก์ด ๊ฐ์ฒด ์์ฑ
const BadExample = () => {
const [animValue] = useState(new Animated.Value(0)); // ๋ฆฌ๋ ๋๋ง๋ง๋ค ์๋ก ์์ฑ!
return <Animated.View style={{ opacity: animValue }} />;
};
// โ
์ข์ ์์: useRef๋ก ์ธ์คํด์ค ์ ์ง
const GoodExample = () => {
const animValue = useRef(new Animated.Value(0)).current; // ํ ๋ฒ๋ง ์์ฑ!
return <Animated.View style={{ opacity: animValue }} />;
};
3๏ธโฃ ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐฉ์ง
์ปดํฌ๋ํธ๊ฐ ์ธ๋ง์ดํธ๋ ๋ ์คํ ์ค์ธ ์ ๋๋ฉ์ด์
์ ์ ๋ฆฌํด์ผ ํด!
์ ๊ทธ๋ฌ๋ฉด ๋ฉ๋ชจ๋ฆฌ ๋์๊ฐ ๋ฐ์ํ ์ ์์ด. ๐ง
useEffect(() => {
const animation = Animated.timing(fadeAnim, {
toValue: 1,
duration: 2000,
useNativeDriver: true
});
animation.start();
// ํด๋ฆฐ์
ํจ์๋ก ์ ๋๋ฉ์ด์
์ ๋ฆฌ
return () => {
animation.stop(); // ์ปดํฌ๋ํธ ์ธ๋ง์ดํธ ์ ์ค์ง
};
}, []);
4๏ธโฃ ๋ณต์กํ ๊ณ์ฐ์ useMemo ํ์ฉ
const AnimatedComponent = () => {
const animValue = useRef(new Animated.Value(0)).current;
// ๋ณต์กํ interpolate ๊ณ์ฐ์ useMemo๋ก ์บ์ฑ
const animatedStyle = useMemo(() => ({
transform: [
{
translateY: animValue.interpolate({
inputRange: [0, 1],
outputRange: [0, -100]
})
},
{
scale: animValue.interpolate({
inputRange: [0, 1],
outputRange: [1, 1.5]
})
}
]
}), [animValue]);
return <Animated.View style={animatedStyle} />;
};
๐จ ์ค์ ํ๋ก์ ํธ: ์ธ์คํ๊ทธ๋จ ์คํ์ผ ์ข์์ ์ ๋๋ฉ์ด์
์ด์ ๋ฐฐ์ด ๊ฑธ ๋ค ํ์ฉํด์ ์ง์ง ์ฑ์์ ์ธ ๋งํ ๊ฑธ ๋ง๋ค์ด๋ณด์!
์ธ์คํ๊ทธ๋จ์ฒ๋ผ ๋๋ธ ํญํ๋ฉด ํํธ๊ฐ ๋ฟ
๋์ค๋ ํจ๊ณผ๋ฅผ ๊ตฌํํด๋ณผ๊ฒ. ๐
import React, { useRef, useState } from 'react';
import {
Animated,
TouchableWithoutFeedback,
View,
Image,
StyleSheet
} from 'react-native';
const InstagramLike = ({ imageUrl }) => {
const [liked, setLiked] = useState(false);
const [lastTap, setLastTap] = useState(0);
// ํํธ ์ ๋๋ฉ์ด์
๊ฐ๋ค
const scaleAnim = useRef(new Animated.Value(0)).current;
const opacityAnim = useRef(new Animated.Value(1)).current;
// ์ข์์ ๋ฒํผ ์ ๋๋ฉ์ด์
const likeButtonScale = useRef(new Animated.Value(1)).current;
const handleDoubleTap = () => {
const now = Date.now();
const DOUBLE_TAP_DELAY = 300;
if (now - lastTap < DOUBLE_TAP_DELAY) {
// ๋๋ธ ํญ ๊ฐ์ง!
if (!liked) {
setLiked(true);
animateHeart();
animateLikeButton();
}
}
setLastTap(now);
};
const animateHeart = () => {
// ์ด๊ธฐํ
scaleAnim.setValue(0);
opacityAnim.setValue(1);
// ํํธ ์ ๋๋ฉ์ด์
์ํ์ค
Animated.sequence([
// 1. ํฌ๊ฒ ์ปค์ง๋ฉด์ ๋ํ๋จ
Animated.parallel([
Animated.spring(scaleAnim, {
toValue: 1,
friction: 3,
useNativeDriver: true
}),
Animated.timing(opacityAnim, {
toValue: 1,
duration: 200,
useNativeDriver: true
})
]),
// 2. ์ ์ ๋๊ธฐ
Animated.delay(400),
// 3. ์ฌ๋ผ์ง
Animated.parallel([
Animated.timing(scaleAnim, {
toValue: 1.2,
duration: 300,
useNativeDriver: true
}),
Animated.timing(opacityAnim, {
toValue: 0,
duration: 300,
useNativeDriver: true
})
])
]).start();
};
const animateLikeButton = () => {
// ์ข์์ ๋ฒํผ ํตํต ํ๋ ํจ๊ณผ
Animated.sequence([
Animated.timing(likeButtonScale, {
toValue: 0.8,
duration: 100,
useNativeDriver: true
}),
Animated.spring(likeButtonScale, {
toValue: 1,
friction: 3,
tension: 40,
useNativeDriver: true
})
]).start();
};
const toggleLike = () => {
setLiked(!liked);
animateLikeButton();
};
return (
<View style={styles.container}>
{/* ์ด๋ฏธ์ง ์์ญ */}
<TouchableWithoutFeedback onPress={handleDoubleTap}>
<View style={styles.imageContainer}>
<Image
source={{ uri: imageUrl }}
style={styles.image}
resizeMode="cover"
/>
{/* ์ค์ ํํธ ์ ๋๋ฉ์ด์
*/}
<Animated.View
style={[
styles.centerHeart,
{
opacity: opacityAnim,
transform: [{ scale: scaleAnim }]
}
]}
>
<Text style={styles.heartIcon}>โค๏ธ</Text>
</Animated.View>
</View>
</TouchableWithoutFeedback>
{/* ํ๋จ ์ข์์ ๋ฒํผ */}
<View style={styles.actionBar}>
<TouchableWithoutFeedback onPress={toggleLike}>
<Animated.View
style={{
transform: [{ scale: likeButtonScale }]
}}
>
<Text style={styles.likeButton}>
{liked ? 'โค๏ธ' : '๐ค'}
</Text>
</Animated.View>
</TouchableWithoutFeedback>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
borderRadius: 12,
overflow: 'hidden',
marginVertical: 10
},
imageContainer: {
width: '100%',
height: 400,
position: 'relative',
backgroundColor: '#f0f0f0'
},
image: {
width: '100%',
height: '100%'
},
centerHeart: {
position: 'absolute',
top: '50%',
left: '50%',
marginLeft: -50,
marginTop: -50,
width: 100,
height: 100,
justifyContent: 'center',
alignItems: 'center'
},
heartIcon: {
fontSize: 100
},
actionBar: {
flexDirection: 'row',
padding: 12,
alignItems: 'center'
},
likeButton: {
fontSize: 28,
marginRight: 12
}
});
export default InstagramLike;
๋ง์ง๋ง ํญ ์๊ฐ์ ์ ์ฅํด์ 300ms ์ด๋ด์ ๋ค์ ํญํ๋ฉด ๋๋ธ ํญ์ผ๋ก ์ธ์!
2. Animated.sequence
์ฌ๋ฌ ์ ๋๋ฉ์ด์ ์ ์์ฐจ์ ์ผ๋ก ์คํํด์ ์์ฐ์ค๋ฌ์ด ํ๋ฆ ๋ง๋ค๊ธฐ
3. Animated.parallel
ํฌ๊ธฐ์ ํฌ๋ช ๋๋ฅผ ๋์์ ๋ณ๊ฒฝํด์ ๋ ์ญ๋์ ์ธ ํจ๊ณผ
4. Spring ์ ๋๋ฉ์ด์
ํตํต ํ๋ ๋๋์ผ๋ก ์๋๊ฐ ์๋ UI ๊ตฌํ! ๐ช
๐ Animated API vs ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ์์ ์ ๋๋ฉ์ด์
์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ง์ผ.
๊ฐ๊ฐ์ ์ฅ๋จ์ ์ ๋น๊ตํด๋ณผ๊ฒ! ๐ค
| ๋ผ์ด๋ธ๋ฌ๋ฆฌ | ์ฅ์ | ๋จ์ | ์ถ์ฒ ์ํฉ |
|---|---|---|---|
| Animated API | โข ๊ธฐ๋ณธ ๋ด์ฅ โข ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ์ง์ โข ์์ ์ |
โข ๋ณต์กํ ์ ๋๋ฉ์ด์
๊ตฌํ ์ด๋ ค์ โข ์ฝ๋๊ฐ ๊ธธ์ด์ง ์ ์์ |
๊ธฐ๋ณธ์ ์ธ ์ ๋๋ฉ์ด์
๊ฐ๋จํ ์ธํฐ๋์ |
| Reanimated 2 | โข ๋งค์ฐ ๊ฐ๋ ฅํจ โข ๋ณต์กํ ์ ์ค์ฒ ์ฒ๋ฆฌ โข ์ฑ๋ฅ ์ต๊ณ |
โข ํ์ต ๊ณก์ ๋์ โข ์ถ๊ฐ ์ค์น ํ์ |
๋ณต์กํ ์ ๋๋ฉ์ด์
๊ณ ์ฑ๋ฅ ํ์์ |
| Lottie | โข ๋์์ด๋ ํ์
์ฌ์ โข ๋ณต์กํ ์ ๋๋ฉ์ด์ ๊ฐ๋จํ โข After Effects ํ์ฉ |
โข ํ์ผ ํฌ๊ธฐ โข ๋์ ๋ณ๊ฒฝ ์ด๋ ค์ |
๊ณ ์ ๋ ์ ๋๋ฉ์ด์
์ผ๋ฌ์คํธ ์ ๋๋ฉ์ด์ |
| LayoutAnimation | โข ๋งค์ฐ ๊ฐ๋จ โข ๋ ์ด์์ ๋ณ๊ฒฝ ์๋ |
โข ์ ์ด๋ ฅ ๋ฎ์ โข Android ์ ํ์ |
๊ฐ๋จํ ๋ ์ด์์ ์ ํ |
๐ฏ ์ธ์ Animated API๋ฅผ ์จ์ผ ํ ๊น?
โข ํ์ด๋, ์ฌ๋ผ์ด๋, ์ค์ผ์ผ ๊ฐ์ ๊ธฐ๋ณธ ์ ๋๋ฉ์ด์
โข ๊ฐ๋จํ ์ธํฐ๋ํฐ๋ธ ์์
โข ์์ ์ฑ์ด ์ค์ํ ํ๋ก๋์ ์ฑ
โข ๋ฒ๋ค ํฌ๊ธฐ๋ฅผ ์ต์ํํ๊ณ ์ถ์ ๋
๐ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ณ ๋ คํด์ผ ํ๋ ๊ฒฝ์ฐ
โข ๋ณต์กํ ์ ์ค์ฒ ๊ธฐ๋ฐ ์ ๋๋ฉ์ด์ (Reanimated 2)
โข 60fps ์ด์์ ๊ณ ์ฑ๋ฅ์ด ํ์์ ์ผ ๋ (Reanimated 2)
โข ๋์์ด๋๊ฐ ๋ง๋ ๋ณต์กํ ์ ๋๋ฉ์ด์ (Lottie)
โข ๋ฌผ๋ฆฌ ์์ง์ด ํ์ํ ๊ฒฝ์ฐ (Matter.js + Reanimated)
๊ฐ์ธ์ ์ผ๋ก๋ ์ฒ์ ์์ํ ๋๋ Animated API๋ก ์ถฉ๋ถํด!
๋์ค์ ํ์ํ๋ฉด Reanimated 2๋ก ๋ง์ด๊ทธ๋ ์ด์
ํ๋ ๊ฒ๋ ์ด๋ ต์ง ์์. ๐
์ฐธ๊ณ ๋ก ์ฌ๋ฅ๋ท์์๋ ๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ ๊ฐ๋ฐ ๊ด๋ จ ๋ค์ํ ์ฌ๋ฅ์ ๊ฑฐ๋ํ ์ ์์ด.
์ ๋๋ฉ์ด์
๊ตฌํ์ด ์ด๋ ต๋ค๋ฉด ์ ๋ฌธ๊ฐ์ ๋์์ ๋ฐ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ง! ๐จ
๐ ์์ฃผ ๋ง๋๋ ์๋ฌ์ ํด๊ฒฐ๋ฒ
์ ๋๋ฉ์ด์
๊ตฌํํ๋ค ๋ณด๋ฉด ์ด๋ฐ์ ๋ฐ ์๋ฌ๋ฅผ ๋ง๋๊ฒ ๋ผ.
์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํด๋ดค์ด! ๐ง
โ Error: Attempting to run JS driven animation on animated node...
๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ๋ฅผ ์ฌ์ฉํ ์ ์๋ ์์ฑ์ useNativeDriver: true๋ฅผ ์ค์ ํ์ ๋
ํด๊ฒฐ๋ฒ
// โ ์๋ฌ ๋ฐ์
Animated.timing(widthAnim, {
toValue: 200,
useNativeDriver: true // width๋ ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ๋ฏธ์ง์!
}).start();
// โ
ํด๊ฒฐ
Animated.timing(widthAnim, {
toValue: 200,
useNativeDriver: false // false๋ก ๋ณ๊ฒฝ
}).start();
// ๋๋ transform์ผ๋ก ๋์ฒด
Animated.timing(scaleAnim, {
toValue: 2,
useNativeDriver: true // transform์ ์ง์!
}).start();
โ Warning: Can't perform a React state update on an unmounted component
์ปดํฌ๋ํธ๊ฐ ์ธ๋ง์ดํธ๋ ํ์๋ ์ ๋๋ฉ์ด์ ์ด ๊ณ์ ์คํ๋๊ณ ์์ ๋
ํด๊ฒฐ๋ฒ
useEffect(() => {
const animation = Animated.timing(fadeAnim, {
toValue: 1,
duration: 2000,
useNativeDriver: true
});
animation.start();
// ํด๋ฆฐ์
ํจ์ ์ถ๊ฐ!
return () => {
animation.stop();
};
}, []);
โ ์ ๋๋ฉ์ด์ ์ด ๋ถ๋๋ฝ์ง ์๊ณ ๋๊ฒจ์
1. ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ๋ฅผ ์ฌ์ฉํ์ง ์์
2. ๋ฆฌ๋ ๋๋ง์ด ๋๋ฌด ์์ฃผ ๋ฐ์
3. ๋ณต์กํ ๊ณ์ฐ์ด ๋ฉ์ธ ์ค๋ ๋๋ฅผ ๋ธ๋กํน
ํด๊ฒฐ๋ฒ
// 1. ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ํ์ฑํ
useNativeDriver: true
// 2. useRef๋ก ๊ฐ ๊ด๋ฆฌ
const animValue = useRef(new Animated.Value(0)).current;
// 3. ๋ณต์กํ ๊ณ์ฐ์ useMemo
const animatedStyle = useMemo(() => ({
transform: [{ translateY: animValue }]
}), [animValue]);
// 4. shouldComponentUpdate ์ต์ ํ
const MemoizedComponent = React.memo(AnimatedComponent);
โ interpolate ๊ฐ์ด ์ด์ํด์
inputRange์ outputRange์ ๊ธธ์ด๊ฐ ๋ค๋ฅด๊ฑฐ๋, ๋ฒ์ ์ค์ ์ด ์๋ชป๋จ
ํด๊ฒฐ๋ฒ
// โ ์๋ชป๋ ์์
const rotate = animValue.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '90deg', '180deg'] // ๊ธธ์ด ๋ถ์ผ์น!
});
// โ
์ฌ๋ฐ๋ฅธ ์์
const rotate = animValue.interpolate({
inputRange: [0, 0.5, 1],
outputRange: ['0deg', '90deg', '180deg'] // ๊ธธ์ด ์ผ์น!
});
// extrapolate ์ต์
ํ์ฉ
const scale = animValue.interpolate({
inputRange: [0, 1],
outputRange: [1, 2],
extrapolate: 'clamp' // ๋ฒ์ ๋ฐ ๊ฐ์ ๊ณ ์
});
๐ก ์ค๋ฌด ํ๊ณผ ๋ฒ ์คํธ ํ๋ํฐ์ค
์ค์ ํ๋ก์ ํธ์์ ์ ๋๋ฉ์ด์ ์ ๊ตฌํํ ๋ ์์๋๋ฉด ์ข์ ํ๋ค์ด์ผ! ๐ฏ
1๏ธโฃ ์ ๋๋ฉ์ด์ ๊ฐ ์ฌ์ฌ์ฉํ๊ธฐ
๊ฐ์ ์ ๋๋ฉ์ด์ ์ ์ฌ๋ฌ ๋ฒ ์คํํด์ผ ํ๋ค๋ฉด, ๊ฐ์ ์ฌ์ฌ์ฉํ๋ ๊ฒ ํจ์จ์ ์ด์ผ!
const useAnimatedValue = (initialValue = 0) => {
const animValue = useRef(new Animated.Value(initialValue)).current;
const animate = useCallback((toValue, duration = 300) => {
return Animated.timing(animValue, {
toValue,
duration,
useNativeDriver: true
});
}, [animValue]);
const reset = useCallback(() => {
animValue.setValue(initialValue);
}, [animValue, initialValue]);
return { animValue, animate, reset };
};
// ์ฌ์ฉ ์์
const MyComponent = () => {
const { animValue, animate, reset } = useAnimatedValue(0);
const fadeIn = () => animate(1).start();
const fadeOut = () => animate(0).start();
return (
<Animated.View style={{ opacity: animValue }}>
{/* ์ปจํ
์ธ */}
</Animated.View>
);
};
2๏ธโฃ ์ ๋๋ฉ์ด์ ํ๋ฆฌ์ ๋ง๋ค๊ธฐ
์์ฃผ ์ฐ๋ ์ ๋๋ฉ์ด์ ์ค์ ์ ํ๋ฆฌ์ ์ผ๋ก ๋ง๋ค์ด๋๋ฉด ํธํด! ๐จ
// animations.js
export const AnimationPresets = {
fadeIn: (animValue, duration = 300) =>
Animated.timing(animValue, {
toValue: 1,
duration,
useNativeDriver: true
}),
fadeOut: (animValue, duration = 300) =>
Animated.timing(animValue, {
toValue: 0,
duration,
useNativeDriver: true
}),
bounceIn: (animValue) =>
Animated.spring(animValue, {
toValue: 1,
friction: 3,
tension: 40,
useNativeDriver: true
}),
slideUp: (animValue, distance = 100) =>
Animated.timing(animValue, {
toValue: -distance,
duration: 300,
useNativeDriver: true
})
};
// ์ฌ์ฉ
import { AnimationPresets } from './animations';
AnimationPresets.fadeIn(fadeAnim).start();
3๏ธโฃ ์ ๋๋ฉ์ด์ ์ํ ๊ด๋ฆฌ
๋ณต์กํ ์ ๋๋ฉ์ด์ ์ํ์ค๋ ์ํ ๋จธ์ ์ผ๋ก ๊ด๋ฆฌํ๋ฉด ์ข์!
const useAnimationState = () => {
const [state, setState] = useState('idle');
const animValue = useRef(new Animated.Value(0)).current;
const transitions = {
idle: () => {
setState('animating');
Animated.timing(animValue, {
toValue: 1,
duration: 300,
useNativeDriver: true
}).start(() => setState('completed'));
},
completed: () => {
setState('resetting');
Animated.timing(animValue, {
toValue: 0,
duration: 300,
useNativeDriver: true
}).start(() => setState('idle'));
}
};
const trigger = () => {
if (transitions[state]) {
transitions[state]();
}
};
return { state, animValue, trigger };
};
4๏ธโฃ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
1. React Native Debugger
Performance Monitor๋ฅผ ์ผ์ FPS ํ์ธ
2. Flipper
Layout Inspector๋ก ๋ฆฌ๋ ๋๋ง ์ถ์
3. console.time
์ ๋๋ฉ์ด์ ์คํ ์๊ฐ ์ธก์
console.time('animation');
Animated.timing(animValue, {
toValue: 1,
duration: 300,
useNativeDriver: true
}).start(() => {
console.timeEnd('animation');
});
5๏ธโฃ ์ ๊ทผ์ฑ ๊ณ ๋ คํ๊ธฐ
์ ๋๋ฉ์ด์
์ด ๋ฉ์ง๊ธด ํ์ง๋ง, ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์ข์ ๊ฑด ์๋์ผ.
์ผ๋ถ ์ฌ๋๋ค์ ์ ๋๋ฉ์ด์
๋๋ฌธ์ ์ด์ง๋ฌ์์ ๋๋ ์ ์๊ฑฐ๋ . ๐ต
import { AccessibilityInfo } from 'react-native';
const useReducedMotion = () => {
const [reduceMotion, setReduceMotion] = useState(false);
useEffect(() => {
AccessibilityInfo.isReduceMotionEnabled().then(enabled => {
setReduceMotion(enabled);
});
const subscription = AccessibilityInfo.addEventListener(
'reduceMotionChanged',
setReduceMotion
);
return () => subscription.remove();
}, []);
return reduceMotion;
};
// ์ฌ์ฉ
const MyComponent = () => {
const reduceMotion = useReducedMotion();
const duration = reduceMotion ? 0 : 300; // ๋ชจ์
๊ฐ์ ์ค์ ์ ์ฆ์ ์ ํ
Animated.timing(animValue, {
toValue: 1,
duration,
useNativeDriver: true
}).start();
};
๐ ๊ณ ๊ธ ํ ํฌ๋: ์ปค์คํ ์ด์ง ํจ์
๊ธฐ๋ณธ ์ ๊ณต๋๋ ์ด์ง ํจ์ ๋ง๊ณ , ์ง์ ๋ง๋ค ์๋ ์์ด!
๋ ์ธ๋ฐํ ์ปจํธ๋กค์ด ๊ฐ๋ฅํ์ง. ๐๏ธ
import { Easing } from 'react-native';
// ๊ธฐ๋ณธ ์ ๊ณต ์ด์ง ํจ์๋ค
const easingTypes = {
linear: Easing.linear,
ease: Easing.ease,
quad: Easing.quad,
cubic: Easing.cubic,
elastic: Easing.elastic(1),
bounce: Easing.bounce,
back: Easing.back(1.5),
bezier: Easing.bezier(0.25, 0.1, 0.25, 1)
};
// ์ปค์คํ
์ด์ง ํจ์
const customEasing = Easing.bezier(0.68, -0.55, 0.265, 1.55);
Animated.timing(animValue, {
toValue: 1,
duration: 500,
easing: customEasing,
useNativeDriver: true
}).start();
๐จ ์ค์ ์์ : ์ปค์คํ ์ด์ง์ผ๋ก ๋ฉ์ง ํจ๊ณผ ๋ง๋ค๊ธฐ
const FancyButton = ({ onPress, title }) => {
const scaleAnim = useRef(new Animated.Value(1)).current;
const rotateAnim = useRef(new Animated.Value(0)).current;
const handlePressIn = () => {
Animated.parallel([
Animated.timing(scaleAnim, {
toValue: 0.95,
duration: 100,
easing: Easing.bezier(0.25, 0.1, 0.25, 1),
useNativeDriver: true
}),
Animated.timing(rotateAnim, {
toValue: 1,
duration: 100,
easing: Easing.elastic(1),
useNativeDriver: true
})
]).start();
};
const handlePressOut = () => {
Animated.parallel([
Animated.spring(scaleAnim, {
toValue: 1,
friction: 3,
tension: 40,
useNativeDriver: true
}),
Animated.spring(rotateAnim, {
toValue: 0,
friction: 3,
tension: 40,
useNativeDriver: true
})
]).start();
};
const rotate = rotateAnim.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '5deg']
});
return (
<TouchableWithoutFeedback
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onPress={onPress}
>
<Animated.View
style={{
transform: [
{ scale: scaleAnim },
{ rotate }
],
backgroundColor: '#667eea',
padding: 16,
borderRadius: 12
}}
>
<Text style={{ color: 'white', fontSize: 16, fontWeight: 'bold' }}>
{title}
</Text>
</Animated.View>
</TouchableWithoutFeedback>
);
};
๐ ์ค๋ฌด ํ๋ก์ ํธ ์์ ๋ชจ์
์ด์ ์ง์ง ์ฑ์์ ์ธ ์ ์๋ ์ค์ฉ์ ์ธ ์์ ๋ค์ ๋ชจ์๋ดค์ด!
๋ณต์ฌํด์ ๋ฐ๋ก ์ธ ์ ์๋๋ก ์์ฑ๋ ์๊ฒ ๋ง๋ค์์ผ๋ ์ฐธ๊ณ ํด๋ด. ๐ฑ
1๏ธโฃ ์ค์ผ๋ ํค ๋ก๋ฉ ์ ๋๋ฉ์ด์
const SkeletonLoader = ({ width = '100%', height = 20 }) => {
const shimmerAnim = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.loop(
Animated.timing(shimmerAnim, {
toValue: 1,
duration: 1500,
easing: Easing.linear,
useNativeDriver: true
})
).start();
}, []);
const translateX = shimmerAnim.interpolate({
inputRange: [0, 1],
outputRange: [-350, 350]
});
return (
<View style={{ width, height, backgroundColor: '#e0e0e0', borderRadius: 4, overflow: 'hidden' }}>
<Animated.View
style={{
width: '100%',
height: '100%',
backgroundColor: 'rgba(255, 255, 255, 0.5)',
transform: [{ translateX }]
}}
/>
</View>
);
};
// ์ฌ์ฉ ์์
const LoadingCard = () => (
<View style={{ padding: 16 }}>
<SkeletonLoader width={100} height={100} />
<View style={{ marginTop: 12 }}>
<SkeletonLoader width="80%" height={20} />
<View style={{ marginTop: 8 }}>
<SkeletonLoader width="60%" height={16} />
</View>
</View>
</View>
);
2๏ธโฃ ํ ์คํธ ๋ฉ์์ง ์ ๋๋ฉ์ด์
const Toast = ({ message, visible, onHide }) => {
const translateY = useRef(new Animated.Value(-100)).current;
const opacity = useRef(new Animated.Value(0)).current;
useEffect(() => {
if (visible) {
// ๋ํ๋๊ธฐ
Animated.parallel([
Animated.spring(translateY, {
toValue: 0,
friction: 8,
tension: 40,
useNativeDriver: true
}),
Animated.timing(opacity, {
toValue: 1,
duration: 200,
useNativeDriver: true
})
]).start();
// 3์ด ํ ์๋์ผ๋ก ์ฌ๋ผ์ง๊ธฐ
const timer = setTimeout(() => {
hideToast();
}, 3000);
return () => clearTimeout(timer);
}
}, [visible]);
const hideToast = () => {
Animated.parallel([
Animated.timing(translateY, {
toValue: -100,
duration: 200,
useNativeDriver: true
}),
Animated.timing(opacity, {
toValue: 0,
duration: 200,
useNativeDriver: true
})
]).start(() => {
if (onHide) onHide();
});
};
if (!visible) return null;
return (
<Animated.View
style={{
position: 'absolute',
top: 50,
left: 20,
right: 20,
backgroundColor: '#333',
padding: 16,
borderRadius: 8,
opacity,
transform: [{ translateY }],
zIndex: 1000
}}
>
<Text style={{ color: 'white', fontSize: 14 }}>{message}</Text>
</Animated.View>
);
};
3๏ธโฃ ํ๋ก๊ทธ๋ ์ค ๋ฐ ์ ๋๋ฉ์ด์
const AnimatedProgressBar = ({ progress = 0, color = '#667eea' }) => {
const widthAnim = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.timing(widthAnim, {
toValue: progress,
duration: 500,
easing: Easing.bezier(0.25, 0.1, 0.25, 1),
useNativeDriver: false // width๋ ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ๋ฏธ์ง์
}).start();
}, [progress]);
const width = widthAnim.interpolate({
inputRange: [0, 100],
outputRange: ['0%', '100%']
});
return (
<View style={styles.progressContainer}>
<Animated.View
style={[
styles.progressBar,
{ width, backgroundColor: color }
]}
/>
</View>
);
};
const styles = StyleSheet.create({
progressContainer: {
width: '100%',
height: 8,
backgroundColor: '#e0e0e0',
borderRadius: 4,
overflow: 'hidden'
},
progressBar: {
height: '100%',
borderRadius: 4
}
});
4๏ธโฃ ์ค์์ดํ ์ญ์ ์ ๋๋ฉ์ด์
const SwipeToDelete = ({ children, onDelete }) => {
const translateX = useRef(new Animated.Value(0)).current;
const deleteOpacity = useRef(new Animated.Value(0)).current;
const panResponder = useRef(
PanResponder.create({
onStartShouldSetPanResponder: () => true,
onMoveShouldSetPanResponder: (_, gestureState) => {
return Math.abs(gestureState.dx) > 5;
},
onPanResponderMove: (_, gestureState) => {
if (gestureState.dx < 0) { // ์ผ์ชฝ์ผ๋ก๋ง ์ค์์ดํ
translateX.setValue(gestureState.dx);
const opacity = Math.min(Math.abs(gestureState.dx) / 100, 1);
deleteOpacity.setValue(opacity);
}
},
onPanResponderRelease: (_, gestureState) => {
if (gestureState.dx < -100) {
// ์ญ์ ์คํ
Animated.timing(translateX, {
toValue: -500,
duration: 200,
useNativeDriver: false
}).start(() => {
if (onDelete) onDelete();
});
} else {
// ์์์น
Animated.parallel([
Animated.spring(translateX, {
toValue: 0,
useNativeDriver: false
}),
Animated.timing(deleteOpacity, {
toValue: 0,
duration: 200,
useNativeDriver: false
})
]).start();
}
}
})
).current;
return (
<View style={{ position: 'relative' }}>
{/* ์ญ์ ๋ฒํผ ๋ฐฐ๊ฒฝ */}
<Animated.View
style={{
position: 'absolute',
right: 0,
top: 0,
bottom: 0,
width: 100,
backgroundColor: '#ef4444',
justifyContent: 'center',
alignItems: 'center',
opacity: deleteOpacity
}}
>
<Text style={{ color: 'white', fontWeight: 'bold' }}>์ญ์ </Text>
</Animated.View>
{/* ์ค์์ดํ ๊ฐ๋ฅํ ์ปจํ
์ธ */}
<Animated.View
style={{
transform: [{ translateX }],
backgroundColor: 'white'
}}
{...panResponder.panHandlers}
>
{children}
</Animated.View>
</View>
);
};
props๋ก ์์, ํฌ๊ธฐ, ๋์ ๋ฑ์ ์ปค์คํฐ๋ง์ด์งํ ์ ์๊ฒ ๋ง๋ค๋ฉด
ํ๋ก์ ํธ ์ ์ฒด์์ ์ผ๊ด๋ UX๋ฅผ ์ ์งํ ์ ์์ด. ๐จ
์ฌ๋ฅ๋ท์์๋ ์ด๋ฐ ์ปดํฌ๋ํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ฐ๋ฐ์ด๋
UI/UX ๊ฐ์ ์์ ์ ์๋ขฐํ ์๋ ์์ผ๋ ์ฐธ๊ณ ํด๋ด!
๐ฏ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์, ์ฌ๊ธฐ๊น์ง ์ฝ์๋ค๋ฉด ์ ๋ง ๋๋จํด! ๐
๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ์ Animated API์ ๋ํด ๊ฝค ๋ง์ ๊ฑธ ๋ฐฐ์ ์ ๊ฑฐ์ผ.
์ฒ์์ ๋ณต์กํด ๋ณด์ผ ์ ์์ง๋ง, ์ง์ ์ฝ๋๋ฅผ ์ง๋ณด๋ฉด์ ์ตํ๋ค ๋ณด๋ฉด
์ด๋์ ์์ฐ์ค๋ฝ๊ฒ ์ ๋๋ฉ์ด์
์ ๊ตฌํํ๊ณ ์๋ ์์ ์ ๋ฐ๊ฒฌํ๊ฒ ๋ ๊ฑฐ์ผ! ๐
โข Animated.Value / ValueXY (๊ฐ)
โข Animated.View / Text / Image (์ปดํฌ๋ํธ)
โข timing / spring / decay (์ ๋๋ฉ์ด์ ํ์ )
2. ์ฑ๋ฅ ์ต์ ํ
โข useNativeDriver: true ํ์!
โข transform๊ณผ opacity๋ง ๋ค์ดํฐ๋ธ ๋๋ผ์ด๋ฒ ์ง์
โข useRef๋ก ๊ฐ ๊ด๋ฆฌ, ๋ถํ์ํ ๋ฆฌ๋ ๋๋ง ๋ฐฉ์ง
3. ๊ณ ๊ธ ํ ํฌ๋
โข interpolate๋ก ๊ฐ ๋ณํ
โข parallel, sequence, stagger๋ก ์กฐํฉ
โข ์ปค์คํ ์ด์ง ํจ์๋ก ์ธ๋ฐํ ์ ์ด
4. ์ค๋ฌด ์ ์ฉ
โข ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ ์ค๊ณ
โข ์ ๊ทผ์ฑ ๊ณ ๋ ค (reduceMotion)
โข ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง๊ณผ ์ต์ ํ
์ ๋๋ฉ์ด์
์ ๋จ์ํ '์์๊ฒ ๋ณด์ด๋ ค๊ณ ' ํ๋ ๊ฒ ์๋์ผ.
์ฌ์ฉ์์๊ฒ ํผ๋๋ฐฑ์ ์ฃผ๊ณ , ์ฑ์ ์ํ๋ฅผ ์ง๊ด์ ์ผ๋ก ์ ๋ฌํ๋ฉฐ,
์ ์ฒด์ ์ธ ์ฌ์ฉ์ ๊ฒฝํ์ ํฅ์์ํค๋ ์ค์ํ ์์์ง! ๐
์ฒ์์ ๊ฐ๋จํ ํ์ด๋ ์ธ/์์๋ถํฐ ์์ํด์,
์ ์ ๋ณต์กํ ์ธํฐ๋์
์ ๋ง๋ค์ด๊ฐ๋ค ๋ณด๋ฉด
์ด๋์ ํ๋ก ์์ค์ ์ฑ์ ๋ง๋ค ์ ์์ ๊ฑฐ์ผ! ๐ช
ํน์ ์ ๋๋ฉ์ด์
๊ตฌํ ์ค์ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด,
๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๊ฑฐ๋, ์ปค๋ฎค๋ํฐ์ ์ง๋ฌธํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ.
๋๋ ์ฌ๋ฅ๋ท์์ ์ ๋ฌธ๊ฐ์ ๋์์ ๋ฐ๋ ๊ฒ๋ ๊ณ ๋ คํด๋ด! ๐ค
์, ์ด์ ๋น์ ์ ์ฑ์ ์๋ช
์ ๋ถ์ด๋ฃ์ด๋ด!
๋ฉ์ง ์ ๋๋ฉ์ด์
์ผ๋ก ์ฌ์ฉ์๋ค์ ๊ฐ๋์์ผ๋ณด์! ๐โจ
๐ Happy Animating! ๐
๋น์ ์ ์ฑ์ด ๋์ฑ ์๋๊ฐ ๋์น๊ธธ ๋ฐ๋ผ! ๐ซ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.