Skip to content

Commit b7ec3d1

Browse files
Fix/period day styling (#2559)
* Calendar - add 'disabledByWeekDays' prop + cleaning props * Update src/calendar/header/index.tsx Co-authored-by: Nitzan Yizhar <[email protected]> * PeriodDay - fix styling to match basic day * fix position when marking, fix today style * remove prop description fix --------- Co-authored-by: Nitzan Yizhar <[email protected]>
1 parent dcdb115 commit b7ec3d1

File tree

7 files changed

+131
-99
lines changed

7 files changed

+131
-99
lines changed

example/src/screens/calendarScreen.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {StyleSheet, View, ScrollView, Text, TouchableOpacity} from 'react-native
33
import {Calendar, CalendarUtils} from 'react-native-calendars';
44
import testIDs from '../testIDs';
55

6-
const INITIAL_DATE = '2022-07-06';
6+
const INITIAL_DATE = '2024-11-06';
77

88
const CalendarScreen = () => {
99
const [selected, setSelected] = useState(INITIAL_DATE);
@@ -135,11 +135,10 @@ const CalendarScreen = () => {
135135
current={INITIAL_DATE}
136136
minDate={getDate(-5)}
137137
displayLoadingIndicator
138-
markingType={'period'}
139138
theme={{
140139
calendarBackground: '#333248',
141140
textSectionTitleColor: 'white',
142-
textSectionTitleDisabledColor: 'gray',
141+
textSectionTitleDisabledColor: 'pink',
143142
dayTextColor: 'red',
144143
todayTextColor: 'white',
145144
selectedDayTextColor: 'white',
@@ -161,6 +160,7 @@ const CalendarScreen = () => {
161160
}
162161
}
163162
}}
163+
markingType={'period'}
164164
markedDates={{
165165
[getDate(-2)]: {disabled: true},
166166
[getDate(1)]: {textColor: 'pink'},
@@ -172,9 +172,11 @@ const CalendarScreen = () => {
172172
[getDate(26)]: {color: 'gray'},
173173
[getDate(27)]: {endingDay: true, color: 'gray'}
174174
}}
175-
disabledDaysIndexes={[3]}
176-
disabledByWeekDays={[3]}
175+
firstDay={1}
176+
disabledDaysIndexes={[1]}
177+
disabledByWeekDays={[1]}
177178
disableAllTouchEventsForDisabledDays
179+
onDayPress={(day) => console.warn(`${day.dateString} pressed`)}
178180
/>
179181
</Fragment>
180182
);
@@ -200,7 +202,7 @@ const CalendarScreen = () => {
200202
}
201203
},
202204
[getDate(11)]: {color: '#70d7c7', textColor: 'white', marked: true, dotColor: 'white'},
203-
[getDate(12)]: {color: '#70d7c7', inactive: true},
205+
[getDate(12)]: {color: '#70d7c7', inactive: true, marked: true},
204206
[getDate(13)]: {
205207
endingDay: true,
206208
color: '#50cebb',
@@ -215,7 +217,8 @@ const CalendarScreen = () => {
215217
}}
216218
theme={{
217219
textInactiveColor: '#a68a9f',
218-
textSectionTitleDisabledColor: 'grey',
220+
inactiveDotColor: '#a68a9f'
221+
, textSectionTitleDisabledColor: 'grey',
219222
textSectionTitleColor: '#319e8e',
220223
arrowColor: '#319e8e'
221224
}}

src/calendar/day/basic/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, {Fragment, useCallback, useRef} from 'react';
22
import {TouchableOpacity, Text, View, ViewProps} from 'react-native';
3-
43
import {xdateToData} from '../../../interface';
54
import {Theme, DayState, MarkingTypes, DateData} from '../../../types';
6-
import styleConstructor from './style';
75
import Marking, {MarkingProps} from '../marking';
6+
import styleConstructor from './style';
87

98

109
export interface BasicDayProps extends ViewProps {
@@ -26,10 +25,10 @@ export interface BasicDayProps extends ViewProps {
2625
disableAllTouchEventsForDisabledDays?: boolean;
2726
/** Disable all touch events for inactive days (can be override with disableTouchEvent in markedDates) */
2827
disableAllTouchEventsForInactiveDays?: boolean;
29-
/** Test ID */
30-
testID?: string;
3128
/** Accessibility label */
3229
accessibilityLabel?: string;
30+
/** Test ID */
31+
testID?: string;
3332
}
3433

3534
const BasicDay = (props: BasicDayProps) => {
@@ -47,16 +46,17 @@ const BasicDay = (props: BasicDayProps) => {
4746
children,
4847
testID
4948
} = props;
49+
const dateData = date ? xdateToData(date) : undefined;
5050
const style = useRef(styleConstructor(theme));
51+
5152
const _marking = marking || {};
5253
const isSelected = _marking.selected || state === 'selected';
5354
const isDisabled = typeof _marking.disabled !== 'undefined' ? _marking.disabled : state === 'disabled';
54-
const isInactive = _marking?.inactive;
55-
const isToday = state === 'today';
55+
const isInactive = typeof marking?.inactive !== 'undefined' ? marking.inactive : state === 'inactive';
56+
const isToday = typeof marking?.today !== 'undefined' ? marking.today : state === 'today';
5657
const isMultiDot = markingType === Marking.markings.MULTI_DOT;
5758
const isMultiPeriod = markingType === Marking.markings.MULTI_PERIOD;
5859
const isCustom = markingType === Marking.markings.CUSTOM;
59-
const dateData = date ? xdateToData(date) : undefined;
6060

6161
const shouldDisableTouchEvent = () => {
6262
const {disableTouchEvent} = _marking;
@@ -113,7 +113,7 @@ const BasicDay = (props: BasicDayProps) => {
113113
styles.push(style.current.inactiveText);
114114
}
115115

116-
//Custom marking type
116+
// Custom marking type
117117
if (isCustom && customStyles && customStyles.text) {
118118
styles.push(customStyles.text);
119119
}
@@ -172,8 +172,8 @@ const BasicDay = (props: BasicDayProps) => {
172172
<TouchableOpacity
173173
testID={testID}
174174
style={getContainerStyle()}
175-
disabled={shouldDisableTouchEvent()}
176175
activeOpacity={activeOpacity}
176+
disabled={shouldDisableTouchEvent()}
177177
onPress={!shouldDisableTouchEvent() ? _onPress : undefined}
178178
onLongPress={!shouldDisableTouchEvent() ? _onLongPress : undefined}
179179
accessible

src/calendar/day/basic/style.ts

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,24 @@ export default function styleConstructor(theme: Theme = {}) {
1515
height: 32,
1616
alignItems: 'center'
1717
},
18+
today: {
19+
backgroundColor: appStyle.todayBackgroundColor,
20+
borderRadius: 16
21+
},
22+
selected: {
23+
backgroundColor: appStyle.selectedDayBackgroundColor,
24+
borderRadius: 16
25+
},
26+
1827
text: {
19-
marginTop: constants.isAndroid ? 4 : 6,
2028
fontSize: appStyle.textDayFontSize,
2129
fontFamily: appStyle.textDayFontFamily,
2230
fontWeight: appStyle.textDayFontWeight,
2331
color: appStyle.dayTextColor,
24-
backgroundColor: 'rgba(255, 255, 255, 0)',
32+
backgroundColor: 'rgba(0, 0, 0, 0)',
33+
marginTop: constants.isAndroid ? 4 : 6,
2534
...appStyle.textDayStyle
2635
},
27-
alignedText: {
28-
marginTop: constants.isAndroid ? 4 : 6
29-
},
30-
selected: {
31-
backgroundColor: appStyle.selectedDayBackgroundColor,
32-
borderRadius: 16
33-
},
34-
today: {
35-
backgroundColor: appStyle.todayBackgroundColor,
36-
borderRadius: 16
37-
},
3836
todayText: {
3937
color: appStyle.todayTextColor
4038
},
@@ -47,27 +45,7 @@ export default function styleConstructor(theme: Theme = {}) {
4745
inactiveText: {
4846
color: appStyle.textInactiveColor
4947
},
50-
dot: {
51-
width: 4,
52-
height: 4,
53-
marginTop: 1,
54-
borderRadius: 2,
55-
opacity: 0,
56-
...appStyle.dotStyle
57-
},
58-
visibleDot: {
59-
opacity: 1,
60-
backgroundColor: appStyle.dotColor
61-
},
62-
selectedDot: {
63-
backgroundColor: appStyle.selectedDotColor
64-
},
65-
disabledDot: {
66-
backgroundColor: appStyle.disabledDotColor || appStyle.dotColor
67-
},
68-
todayDot: {
69-
backgroundColor: appStyle.todayDotColor || appStyle.dotColor
70-
},
48+
7149
...(theme['stylesheet.day.basic'] || {})
7250
});
7351
}

src/calendar/day/dot/style.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export default function styleConstructor(theme: Theme = {}) {
2222
backgroundColor: appStyle.selectedDotColor
2323
},
2424
disabledDot: {
25-
backgroundColor: appStyle.disabledDotColor || appStyle.dotColor
25+
backgroundColor: appStyle.disabledDotColor
2626
},
2727
inactiveDot: {
28-
backgroundColor: appStyle.inactiveDotColor || appStyle.dotColor
28+
backgroundColor: appStyle.inactiveDotColor
2929
},
3030
todayDot: {
31-
backgroundColor: appStyle.todayDotColor || appStyle.dotColor
31+
backgroundColor: appStyle.todayDotColor
3232
},
3333
...(theme['stylesheet.dot'] || {})
3434
});

0 commit comments

Comments
 (0)