WeeklyCalendar.js 2.69 KB
Newer Older
1
2
import React, {  useState, useEffect } from 'react';
import { View,  StyleSheet } from 'react-native';
Soo Hyun Kim's avatar
Soo Hyun Kim committed
3
4
import CalendarStrip from 'react-native-calendar-strip';

Soo Hyun Kim's avatar
Soo Hyun Kim committed
5
6
7
8
9
10
11
12
13
14
15
16
17
const WeeklyCalendar = ({
    selectedDate,
    startingDate,
    onWeekChanged,
    onDateSelected,
    weeklyData = [],
    customDatesStyles
}) => {
    const [markedDates, setmarkedDates] = useState([])
    
    useEffect(() => {
        getMarkedDates()
    }, [weeklyData])
Soo Hyun Kim's avatar
Soo Hyun Kim committed
18

Soo Hyun Kim's avatar
Soo Hyun Kim committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    const getMarkedDates = () => {
        if(weeklyData.length === 0) {
            return null;
        }

        const markedData = weeklyData.map(data => {
            return (
                {
                    date: data.date,
                    dots: getDots(data.type_id)
                }
            );
        })

        setmarkedDates(markedData)
    }

    const getDots = (typeArray) => {
        const tempDots = []
        for (let i = 0; i < typeArray.length; i++) {
            if (typeArray[i] === "1") {
                tempDots.push({ color: "#93bdcc", selectedColor: "#7b9e7c", })
            } else {
                tempDots.push({ color: "#d98b79", })
            }
        }
        return tempDots;
    }
Soo Hyun Kim's avatar
Soo Hyun Kim committed
47
48
49
50

    return (
        <View>
            <CalendarStrip
Soo Hyun Kim's avatar
Soo Hyun Kim committed
51
                calendarAnimation={{ type: 'parallel', duration: 30 }}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
52
                daySelectionAnimation={{ type: 'background', duration: 300, highlightColor: '#9265DC' }}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
53
                style={{ height: 130, paddingTop: 20, paddingBottom: 10 }}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
54
                calendarHeaderStyle={{ color: 'white' }}
Choi Ga Young's avatar
Choi Ga Young committed
55
                calendarColor={'#adbfdb'}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
56
57
58
                dateNumberStyle={{ color: 'white' }}
                dateNameStyle={{ color: 'white' }}
                iconContainer={{ flex: 0.1 }}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
59
60
                customDatesStyles={customDatesStyles}
                updateWeek
Soo Hyun Kim's avatar
Soo Hyun Kim committed
61
                highlightDateNameStyle={{ color: 'white' }}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
62
                highlightDateNumberStyle={{ color: 'white' }}
Choi Ga Young's avatar
Choi Ga Young committed
63
                highlightDateContainerStyle={{ backgroundColor: '#6b768a' }}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
64
65
66
67
68
69
                // markedDates={markedDates}
                // datesBlacklist={datesBlacklistFunc}
                // startingDate={startingDate}
                selectedDate={selectedDate}
                onWeekChanged={onWeekChanged}
                onDateSelected={onDateSelected}
Soo Hyun Kim's avatar
Soo Hyun Kim committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
                useIsoWeekday={false}
            />
        </View>
    );
};

const style = StyleSheet.create({
    container: {
        height: 54,
        flexDirection: 'row',
        alignItems: "center",
        marginHorizontal: 10,
        marginVertical: 3,
        borderWidth: 1.5,
        borderStyle: "solid",
        borderColor: "#1467ff",
        borderRadius: 5,
        backgroundColor: "#f5f5f5",
    },
})

export default WeeklyCalendar