
๋ชจ๋ฐ์ผ ์ฑ์ ํต์ฌ UX ์ค ํ๋๋
ํ๋ฉด์ ์๊ฐ๋ฝ์ผ๋ก ๋ฐ์ด์(interact) ๋ฌด์ธ๊ฐ๋ฅผ ์กฐ์ํ๋ ์ ์ค์ฒ๋ค.
ํนํ ์ค์์ดํ(Swipe) ์ ์ค์ฒ๋
์ด๋ฒ ๊ธ์ React Native์์ ์ค์์ดํ ์ ์ค์ฒ๋ฅผ ๊ตฌํํ ์ ์๋ ๋ค์ํ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํ ๊ธ์ด๋ค.
npm install react-native-gesture-handler
ํ์์ ์ผ๋ก ์ค์นํด์ผ ํ๋ ๊ธฐ๋ณธ ์ ์ค์ฒ ํธ๋ค๋ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๋๋ถ๋ถ์ ์ค์์ดํ ๊ธฐ๋ฅ์ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์๋ํจ
import { Swipeable } from 'react-native-gesture-handler';
<Swipeable
renderRightActions={() => (
<TouchableOpacity style={styles.deleteBox}>
<Text style={styles.deleteText}>์ญ์ </Text>
</TouchableOpacity>
)}
>
<View style={styles.listItem}>
<Text>ํ ์ผ ํญ๋ชฉ</Text>
</View>
</Swipeable>
โ
์ข/์ฐ ์ก์
๊ตฌํ ๊ฐ๋ฅ
โ
onSwipeableOpen์ผ๋ก ์ก์
์ฒ๋ฆฌ
โ ์ฌ๋ฌ ํญ๋ชฉ์ด ๋์์ ์ด๋ฆฌ๋ ๋ฌธ์ โ ์ธ๋ถ ์ ์ด ํ์
์ ์ค์ฒ๋ก ์/์๋๋ก ์์ง์ด๋ ์ปดํฌ๋ํธ
react-native-modalize ๋๋ reanimated-bottom-sheet ์ฌ์ฉ<Modalize ref={modalRef} snapPoint={300}>
<Text>์ต์
๋ชฉ๋ก</Text>
</Modalize>
โ
ํฐ์น ์ ์ค์ฒ + ๋ฐ์ด์ค ํจ๊ณผ
โ
scroll, dismiss ์ด๋ฒคํธ ๋ชจ๋ ์ง์
โ
์ค์์ดํ UX ๊ตฌํ์ ํนํ
import {
PanGestureHandler,
GestureHandlerRootView,
} from 'react-native-gesture-handler';
import Animated, {
useSharedValue,
useAnimatedGestureHandler,
useAnimatedStyle,
withSpring,
} from 'react-native-reanimated';
const translateX = useSharedValue(0);
const panGesture = useAnimatedGestureHandler({
onActive: (event) => {
translateX.value = event.translationX;
},
onEnd: () => {
translateX.value = withSpring(0);
},
});
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ translateX: translateX.value }],
}));
<GestureHandlerRootView>
<PanGestureHandler onGestureEvent={panGesture}>
<Animated.View style={[styles.box, animatedStyle]} />
</PanGestureHandler>
</GestureHandlerRootView>
โ
์์ ๋ ๋์ ์ ์ค์ฒ ๊ตฌํ
โ
UI ์ปดํฌ๋ํธ์ ์ง์ ์ ์ธ ์์ง์ ์ ์ด ๊ฐ๋ฅ
โ
๋๋๊ทธ, ์ค์์ดํ, ์ฌ๋ผ์ด๋ ๋ฑ ๋ชจ๋ ์ ํ ๊ตฌํ ๊ฐ๋ฅ
โ ๋ฌ๋ ์ปค๋ธ ์กด์ฌ
| ํญ๋ชฉ | ์ ๋ต |
|---|---|
| ๋ฆฌ์คํธ ํญ๋ชฉ ์ญ์ | Swipeable ์ปดํฌ๋ํธ ํ์ฉ |
| ๋ฐํ ์ํธ ์ ์ค์ฒ | Modalize, Reanimated Bottom Sheet |
| ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋ | ScrollView horizontal, ๋๋ PanGesture |
| ์ ์ค์ฒ ์ค๋ณต ๋ฐฉ์ง | GestureHandler context ์ ํ or exclusive ์ฒ๋ฆฌ |
| ์ข ๋ฃ ์ ๋๋ฉ์ด์ | withSpring, withTiming ํ์ฉํด์ ์์ฐ์ค๋ฝ๊ฒ |
์ด๊ธฐ์๋ ๋ชจ๋ ์ค์์ดํ UI๋ฅผ ๊ทธ๋ฅ ScrollView๋ก ์ฒ๋ฆฌํ๋๋ฐ,
UX๊ฐ ์ด์ํ๊ณ , ๋์์ด ๊ธฐ๊ธฐ๋ง๋ค ๋ค๋ฅด๊ฒ ๋๊ปด์ก๋ค.
์ง๊ธ์ Swipeable๋ก ๊ธฐ๋ณธ ์ ์ค์ฒ ์ฒ๋ฆฌํ๊ณ ,
ํ๋จ ์ธํฐ๋์
์ Modalize + Reanimated๋ก ๋ถ๋๋ฝ๊ฒ ์ฒ๋ฆฌํ๊ณ ์๋ค.
์ง์ ์ ์ด๊ฐ ํ์ํ ๊ฒฝ์ฐ์ PanGesture๋ฅผ ์กฐํฉํด์ ๊ณ ๊ธ UI๋ฅผ ๋ง๋ ๋ค.
๐ โ์ค์์ดํ๋ UI๊ฐ ์๋๋ผ, ๊ฐ๊ฐ์ด๋ค. ์ฑ์ ์๋ง์ ์ฌ๊ธฐ์ ๋์จ๋ค.โ