-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathcalendarListScreen.tsx
121 lines (111 loc) Β· 2.73 KB
/
calendarListScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, {useState, useMemo, useCallback} from 'react';
import {StyleSheet, Text, View, TextStyle} from 'react-native';
import {CalendarList, DateData} from 'react-native-calendars';
import testIDs from '../testIDs';
const RANGE = 24;
const initialDate = '2022-07-05';
const nextWeekDate = '2022-07-14';
const nextMonthDate = '2022-08-05';
interface Props {
horizontalView?: boolean;
}
const CalendarListScreen = (props: Props) => {
const {horizontalView} = props;
const [selected, setSelected] = useState(initialDate);
const marked = useMemo(() => {
return {
[nextWeekDate]: {
selected: selected === nextWeekDate,
selectedTextColor: '#5E60CE',
marked: true
},
[nextMonthDate]: {
selected: selected === nextMonthDate,
selectedTextColor: '#5E60CE',
marked: true
},
[selected]: {
selected: true,
disableTouchEvent: true,
selectedColor: '#5E60CE',
selectedTextColor: 'white'
}
};
}, [selected]);
const onDayPress = useCallback((day: DateData) => {
setSelected(day.dateString);
}, []);
return (
<CalendarList
testID={testIDs.calendarList.CONTAINER}
current={initialDate}
pastScrollRange={RANGE}
futureScrollRange={RANGE}
onDayPress={onDayPress}
markedDates={marked}
renderHeader={!horizontalView ? renderCustomHeader : undefined}
calendarHeight={!horizontalView ? 390 : undefined}
theme={!horizontalView ? theme : undefined}
horizontal={horizontalView}
pagingEnabled={horizontalView}
staticHeader={horizontalView}
inverted={false}
/>
);
};
const theme = {
stylesheet: {
calendar: {
header: {
dayHeader: {
fontWeight: '600',
color: '#48BFE3'
}
}
}
},
'stylesheet.day.basic': {
today: {
borderColor: '#48BFE3',
borderWidth: 0.8
},
todayText: {
color: '#5390D9',
fontWeight: '800'
}
}
};
function renderCustomHeader(date: any) {
const header = date.toString('MMMM yyyy');
const [month, year] = header.split(' ');
const textStyle: TextStyle = {
fontSize: 18,
fontWeight: 'bold',
paddingTop: 10,
paddingBottom: 10,
color: '#5E60CE',
paddingRight: 5
};
return (
<View style={styles.header}>
<Text style={[styles.month, textStyle]}>{`${month}`}</Text>
<Text style={[styles.year, textStyle]}>{year}</Text>
</View>
);
}
export default CalendarListScreen;
const styles = StyleSheet.create({
header: {
flexDirection: 'row',
width: '100%',
justifyContent: 'space-between',
marginTop: 10,
marginBottom: 10
},
month: {
marginLeft: 5
},
year: {
marginRight: 5
}
});