WeeklyCalendar.js 2.8 KB
Newer Older
Soo Hyun Kim's avatar
Soo Hyun Kim committed
1
import React, { Component, useState, useEffect } from 'react';
Soo Hyun Kim's avatar
Soo Hyun Kim committed
2
3
4
import { View, Text, Button, StyleSheet } from 'react-native';
import CalendarStrip from 'react-native-calendar-strip';
// import moment from 'moment';
Soo Hyun Kim's avatar
Soo Hyun Kim committed
5
import { getDateStr } from '../utils/dateFunction';
Soo Hyun Kim's avatar
Soo Hyun Kim committed
6

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

Soo Hyun Kim's avatar
Soo Hyun Kim committed
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
47
48
    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
49
50
51
52

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