[React Native] Google Forms ํด๋ก ํ๋ก์ ํธ
Google Forms Clone Project
0. TypeScript + React Native + Recoil๋ก ๊ตฌํํ ํ ์ด ํ๋ก์ ํธ
- 3์ผ๋์ ํผ์์ Google Forms์ ์ต์ ๊ธฐ๋ฅ์ ๊ตฌํ
- Expo๋ก React Native๋ฅผ ์ค์นํด์ ์์
- ๊ณผ๊ฑฐ ํ๋ก์ ํธ๋ ์ง์ ์๋ฎฌ๋ ์ดํฐ๋ฅผ ๋๋ฆฌ๋ฉด์ ๊ตฌํํ๋๋ฐ, ์ ๋ง ์๋ฎฌ๋ ์ดํฐ ํฌ๋๋ง๋ค ๊ณ ์ญ์ด์๋ค.
- Expo๋ก ์์ ํ๋ ์์ฃผ ๊ฐํธํ์ผ๋ ์ด๊ฒ๋ ๋ง๋ฅ์ ์๋๋ฏ.. ๊ฐ์๊ธฐ ์คํ ์๋ฌ๊ฐ ๋ ์ ์ ๋จน์๋ค.
- Recoil๋ก ๋ชจ๋ state๋ฅผ ์ ์ญ ๊ด๋ฆฌ
- StyleSheet๋ก ์คํ์ผ๋ง
1. ๊ธฐ๊ฐ
- 2024.05.17 ~ 19์ผ
2. ์คํ
- TypeScript
- React Native
- Recoil
- UI ๋ผ์ด๋ธ๋ฌ๋ฆฌ(์ก์ ์ํธ..)
3. ๊ตฌํ ์ฌํญ
- ์ค๋ฌธ ์์ฑ
- ์ค๋ฌธ ์ถ๊ฐ, ์ญ์ , ๋ณต์ฌ
- ๋จ๋ต, ์ฅ๋ฌธ, ๊ฐ๊ด์, ์ฒดํฌ๋ฐ์ค
- ์ค๋ฌธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
4. ๊ธฐ์ตํ๊ณ ์ถ์ ์ฝ๋ ๋ฐ ์์ฌ์ด ์
์ค๋ฌธ ๋ฆฌ์คํธ๋ฅผ ์ ๋ฐ์ดํธ ํ๋ ํจ์
const updateSurveyList = (
id: number,
action: "toggleSwitch" | "inputFocus" | "inputBlur"
) => {
const updatedSurveyList = surveyList.map((item) => {
if (item.id === id) {
switch (action) {
case "toggleSwitch":
return {
...item,
isEnabled: !item.isEnabled,
};
case "inputFocus":
return {
...item,
titleInputFocus: true,
};
case "inputBlur":
return {
...item,
titleInputFocus: false,
};
default:
return item;
}
}
return item;
});
setSurveyList(updatedSurveyList);
};
์ค๋ฌธ ๋ฆฌ์คํธ๊ฐ ๊ฐ์ฒด๋ก ์ด๋ฃจ์ด์ง ๋ฐฐ์ด์ด๊ธฐ ๋๋ฌธ์
๊ฐ์ฒด ์์ ์์ฑ์ ์ ๋ฐ์ดํธ๋ฅผ ํ๋ ค๋ฉด ์ฐ์ , ๋ฆฌ์คํธ๋ฅผ map์ผ๋ก ์ํํด์ค๋ค.
๊ทธ๋ฆฌ๊ณ ํด๋ฆญํ ๋ ๋๊ฒจ์ค ํด๋น ์ค๋ฌธ id์ ๋์ผํ id์ ๊ฐ์ฒด๋ฅผ ์ฐพ์ผ๋ฉด ๋ณ๊ฒฝํด์ return ํด์ฃผ๊ณ
๋๋จธ์ง๋ ๊ทธ๋๋ก returnํด์ ๋ณ๊ฒฝ๋ ๋ฆฌ์คํธ๋ฅผ setState ํด์ฃผ๋ ํจ์.
์์งํ ์ด๋ฐ ๊ธฐ๋ฅ๋ค todo list ๋ง๋ค ๋ ํ๋ ๊ฒ๋ค์ธ๋ฐ ์ค๋๋ง์ ํ๋ก์ ํธ๋ฅผ ํด๋ณด๋
์ด๊ฒ๋ ๋ฒ๋ฒ ๋ฒ๋ฒ ..
inline style ์ฌ์ฉ์ ์ง์ํ์
{survey.option === "๋จ๋ตํ" && (
<View style={{ borderBottomWidth: 1, width: 180, borderColor: "#E9E9E9"}}>
<Text style={styles.optionText}>๋จ๋ตํ ํ
์คํธ</Text>
</View>
)}
Stylesheet๋ฅผ ์ ์ํ๋ฉด์ ์ฌ์ฉํด๋๊ณ ์ ์ด๋ ๊ฒ inline style์ ์ฌ์ฉํ์๊น?
๊ฐ๋ ์ฑ์ ๋จ์ด์ง๊ณ , ์คํ์ผ์ ํ ๊ณณ์์ ํ์ธํ ์ ์์์..
๊ตฌํํ๋ค๊ณ ์ ์ ์์ด์ ๋๋ฌด ์ด๋ฐ๊ฑฐ์ ์ ๊ฒฝ์ ์์ด ๊ฒ ๊ฐ๋ค.
์์ผ๋ก๋ inline style์ ์ง์ํ๋๋ก ํด์ผ๊ฒ ๋ค..
๋ณต์กํ ์ต๋ช ํจ์๋ ์ ์ธํ์ฌ ์ฌ์ฉํ์
<Pressable
style={styles.actionButton}
onPress={() => actionSheetRef.current?.show()}
>
onPress ํ๋กํผํฐ ์์ ๋ง ์ ์ง๋ง๊ณ ๊ฐ๋ ์ฑ์ ์ํด ํจ์๋ ์ ์ธํด์ ์ฌ์ฉํ์.
style์ style๋ผ๋ฆฌ, ํจ์๋ ํจ์๋ผ๋ฆฌ ๋นผ์ ๋ ๋ฆฝ์ ์ผ๋ก ๊ด๋ฆฌํ์
๋ฆฌํด๋ฌธ ์์๋ ํจ์๊ฐ, ์๋์๋ Stylesheet๋ฅผ ๋๋๊น ์ ์ฒด์ ์ผ๋ก ํ ํ์ผ ์์ ์ฝ๋๊ฐ ๋๋ฌด ๋ง๊ณ
๊ฐ๋ ์ฑ๋ ์๊ณ ๋์ค์ ์ ์ง๋ณด์ ํ๊ธฐ๋ ํ๋ค์ด๋ณด์ธ๋ค.
์์ผ๋ก๋ ๋ฐ๋ก ํ์ผ๋ก ๋นผ์ import ํ๋ ๊ฒ ๋ ์ข์ ๊ฑฐ ๊ฐ๋ค.