728x90
๋ฐ์ํ
์น์ผ๋ก ์ฐ๊ณ ์๋ ToT๋ฅผ app์ผ๋ก ์ฎ๊ธฐ๊ธฐ๋ก ๊ฒฐ์ ํ๋ฉด์ UI๋ถ๋ถ๋ ๋ง์ด ๋ณ๊ฒฝ๋์๋ค.
๊ทธ ๊ณผ์ ์์ home์ weekly ์บ๋ฆฐ๋๋ฅผ ๋ฃ๊ฒ ๋์๋๋ฐ React-Native๋ ์ฒ์์ด๊ธฐ๋ํ๊ณ ๊ฐ์ด ์ ์ ์กํ์ ์บ๋ฆฐ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฐพ์๋ณด๋ค๊ฐ ์ฌ์ฉํ๊ฒ ๋ calendar-strip
๊ตฌํ์ด ํ์ํ ๊ธฐ๋ฅ
- weekly๋ก ๋ณด์ฌ์ผํจ
- ์์ผ๋ณ๋ก ํด๋ฆญ์ด ๊ฐ๋ฅํด์ผํจ
- ์์ผ์ด ํด๋ฆญ๋๋ฉด ํด๋น ์์ผ์ ๋ฐ์ดํฐ๋ค์ด ๋ณด์ฌ์ผํจ
- ํ์ดํ๋ฅผ ํด๋ฆญํ๋ฉด ์ฃผ๋ณ๋ก ์ด๋์ด ๋์ด์ผํจ
- ๋ฐ์ดํฐ๊ฐ ์๋ ์์ผ์ ์์ผ์ ํ์๊ฐ ๋์ด์์ด์ผํจ
์ฌ์ฉํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๋ด๊ฐ ํ์ํ๋ ๋ชจ๋ ๊ธฐ๋ฅ์ด ์์ฝ๊ฒ ๊ตฌํ์ด ๊ฐ๋ฅํ๊ณ ๋ค์ํ demo ๋ฒ์ ผ์ด ๋ง๋ค์ด์ ธ์์ด์ ์ฌ์ฉ ๋ฐฉ๋ฒ์ด ์์ธํ ์ค๋ช ๋์ด์๋ต๋๋ค
https://www.npmjs.com/package/react-native-calendar-strip
https://github.com/BugiDev/react-native-calendar-strip
์ฝ๋ ๋ธ๋ก
expo๋ก ์ฑ์ ๋ง๋ค๊ณ ์์๋๋ฐ
npm install react-native-calendar-strip
์ผ๋ก ์ค์นํด์ฃผ๊ณ ์์ํ๋ฉด ๋๋ค.
<CalendarStrip
showMonth={false} // month ํค๋ ์์ ๊ธฐ
style={{ height: 80, paddingTop: 0, paddingBottom: 0 }}
calendarColor={"#ffffff"}
calendarHeaderStyle={{ color: "black" }}
dateNumberStyle={{ color: "black" }}
dateNameStyle={{ color: "black" }}
highlightDateContainerStyle={{ backgroundColor: "#647ce6" }} //๋๊ทธ๋ผ๋ฏธ ๋ฐฑ๊ทธ๋ผ์ด๋
iconContainer={{ flex: 0.1 }}
highlightDateNumberStyle={{ color: "white" }} // ํ์ด๋ผ์ดํธ๋ ์์ผ์ปฌ๋ฌ
highlightDateNameStyle={{ color: "white" }}
selectedDate={selectedDate} // ์ ํ๋ ๋ ์ง
onWeekChanged={handleWeekChange} // ์ฃผ๊ฐ ๋ณ๊ฒฝ๋ ๋
onDateSelected={handleDateSelect} // ์์ผ์ ๋๋ ์ ๋ ๋์ฌ ํจ์
markedDates={markedDate} // ์์ผ ๋ฐ์ ๋๊ทธ๋ผ๋ฏธ ๋งํฌ ํ์ํด์ฃผ๊ธฐ
/>
const handleDateSelect = (date: any) => {
setSelectedDate(date); // ์ ํ๋ ๋ ์ง๋ฅผ ์ํ์ ์ ์ฅ
const selected = moment(date);
const year = selected.year(); // 2024
const month = selected.month() + 1; // 10 (0๋ถํฐ ์์ํ๋ฏ๋ก +1)
const day = selected.date();
// ์์ผ์ด ๋ณ๊ฒฝ๋ ๋๋ง๋ค ํด๋น ๋ ์ง์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํ data fetch
// ์์ผ ๋ฐ์ data ํ์ํด์ค์ผํด์ ๊ฐ์ ธ์ค๋ ๊ฒ -
// ์บ๋ฆฐ๋์ ์๊ด์์
fetchRecords(user.$id, year, month, day).then(
([todayRecordRes, todayTotalRecordRes]) => {
setTodayRecord(todayRecordRes);
setTodayTotalRecord(todayTotalRecordRes);
}
);
setCurrentMonth(selected.format('MM')); // ์ฃผ ์์ ๋ ์ง ๊ธฐ์ค์ผ๋ก ์ ์
๋ฐ์ดํธ
setCurrentYear(selected.format('YYYY'))
};
const handleWeekChange = (startOfWeek : any) => {
// ์์ผ์ ๋ณ๊ฒฝํ๋ ํ์ดํ๋ฅผ ๋๋ ์ ๋ ์ฃผ์ ์์์ ์ด ์๋๋ผ ์ฃผ์ ๋ง์ง๋ง ๋ ์ ์ด์ ์ด ๋๊ฒ ์ค์
// ๊ทธ๋์ add 6์ด ๋๋ค.
// ์์ผ ๋ฐ๊พธ๋ฉด ์ฃผ์ ์์์ ์ผ๋ก ์ด๋ํ๋๊ฒ ๋ํดํธ๊ฐ
setCurrentWeekStart(startOfWeek.add(6, 'days'));
// ์ฃผ๊ฐ ๋ฐ๋ ๋ 6์ผ์น weekly data๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํ data fetch
// ๊ฐ์ ธ์์ mark๋ฅผ ์ํ ํจ์์ ๋ฃ์ด์ค๋ค
getWeeklyRecords(user.$id, startOfWeek, 7).then((res) => {
checkingForMark(res);
});
};
// ์ด๋ฐ ๋ฐฐ์ด ํํ๋ก ๋ค์ด๊ฐ์ผํ๋ค
// ์ด๊ฑด ์์์ผ ๋ฟ. ํ์ํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ๊ณตํด์ array ๋ชจ์์ผ๋ก ๋ง๋ค์ด์ฃผ๋ฉด ๋จ
const markedDate = [{
date: moment(),
dots: [{ color: "#647ce6", selectedColor: "white" }],
}]
๊ฒฐ๊ณผ๋ฌผ
728x90
'๊ฐ๋ฐ > React-Native' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
(ios) EAS๋ก expo ๋น๋ํ๊ณ testFlight์ ๋ฑ๋กํ๊ธฐ (feat.์ค๋ฅ) (0) | 2024.11.22 |
---|---|
[React Native] React Nativgation ์ ์ฉํ๊ธฐ - 2 (0) | 2022.03.16 |
[React Native] React Nativgation ์ ์ฉํ๊ธฐ - 1 (0) | 2022.03.09 |
[React Native] AppLoading (0) | 2022.02.28 |
[React-Native] ๋ฆฌ์กํธ ๋ค์ดํฐ๋ธ ์์ํ๊ธฐ( with Expo) (0) | 2022.02.21 |