Skip to content

Commit 038a96d

Browse files
author
Tautvilas Mecinskas
committed
refactor interactive marking type into period marking type
1 parent 39b4123 commit 038a96d

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const workout = {key:'workout', color: 'green'};
145145
```
146146

147147

148-
Interval marking
148+
Period marking
149149

150150
<kbd>
151151
<img height=50 src="https://github.com/wix-private/wix-react-native-calendar/blob/master/demo/marking2.png?raw=true">
@@ -159,13 +159,13 @@ Interval marking
159159
<Calendar
160160
// Collection of dates that have to be colored in a special way. Default = {}
161161
markedDates={
162-
{'2012-05-20': [{textColor: 'green'}],
163-
'2012-05-22': [{startingDay: true, color: 'green'}],
164-
'2012-05-23': [{endingDay: true, color: 'green', textColor: 'gray'}],
165-
'2012-05-04': [{startingDay: true, color: 'green'}, {endingDay: true, color: 'green'}]
162+
{'2012-05-20': {periods: [{textColor: 'green'}]},
163+
'2012-05-22': {periods: [{startingDay: true, color: 'green'}]},
164+
'2012-05-23': {periods: [{endingDay: true, color: 'green', textColor: 'gray'}]},
165+
'2012-05-04': {disabled: true, periods: [{startingDay: true, color: 'green'}, {endingDay: true, color: 'green'}]}
166166
}}
167-
// Date marking style [simple/interactive/multi-dot]. Default = 'simple'
168-
markingType={'interactive'}
167+
// Date marking style [simple/period/multi-dot]. Default = 'simple'
168+
markingType={'period'}
169169
/>
170170
```
171171

example/src/screens/calendars.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ export default class CalendarsScreen extends Component {
4444
current={'2012-05-16'}
4545
minDate={'2012-05-10'}
4646
displayLoadingIndicator
47-
markingType={'interactive'}
47+
markingType={'period'}
4848
theme={{
4949
calendarBackground: '#333248',
5050
textSectionTitleColor: 'white',
51-
dayTextColor: 'white',
51+
dayTextColor: 'red',
5252
todayTextColor: 'white',
5353
selectedDayTextColor: 'white',
5454
monthTextColor: 'white',
5555
selectedDayBackgroundColor: '#333248',
5656
arrowColor: 'white',
57+
// textDisabledColor: 'red',
5758
'stylesheet.calendar.header': {
5859
week: {
5960
marginTop: 5,
@@ -63,14 +64,15 @@ export default class CalendarsScreen extends Component {
6364
}
6465
}}
6566
markedDates={{
66-
'2012-05-08': [{textColor: '#666'}],
67-
'2012-05-09': [{textColor: '#666'}],
68-
'2012-05-14': [{startingDay: true, color: 'blue'}, {endingDay: true, color: 'blue'}],
69-
'2012-05-21': [{startingDay: true, color: 'blue'}],
70-
'2012-05-22': [{endingDay: true, color: 'gray'}],
71-
'2012-05-24': [{startingDay: true, color: 'gray'}],
72-
'2012-05-25': [{color: 'gray'}],
73-
'2012-05-26': [{endingDay: true, color: 'gray'}]}}
67+
'2012-05-17': {disabled: true},
68+
'2012-05-08': {periods: [{textColor: '#666'}]},
69+
'2012-05-09': {periods: [{textColor: '#666'}]},
70+
'2012-05-14': {periods: [{startingDay: true, color: 'blue'}, {endingDay: true, color: 'blue'}]},
71+
'2012-05-21': {periods: [{startingDay: true, color: 'blue'}]},
72+
'2012-05-22': {periods: [{endingDay: true, color: 'gray'}]},
73+
'2012-05-24': {periods: [{startingDay: true, color: 'gray'}]},
74+
'2012-05-25': {periods: [{color: 'gray'}]},
75+
'2012-05-26': {periods: [{endingDay: true, color: 'gray'}]}}}
7476
hideArrows={false}
7577
/>
7678
<Calendar

src/calendar/day/interactive/index.js renamed to src/calendar/day/period/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Day extends Component {
2929
super(props);
3030
this.theme = {...defaultStyle, ...(props.theme || {})};
3131
this.style = styleConstructor(props.theme);
32-
this.markingStyle = this.getDrawingStyle(props.marked);
32+
this.markingStyle = this.getDrawingStyle(props.marked || []);
3333
this.onDayPress = this.onDayPress.bind(this);
3434
}
3535

@@ -54,11 +54,14 @@ class Day extends Component {
5454
}
5555

5656
getDrawingStyle(marking) {
57+
const defaultStyle = {textStyle: {}};
5758
if (!marking) {
58-
return {};
59+
return defaultStyle;
5960
}
60-
return marking.reduce((prev, next) => {
61-
prev.textStyle = {};
61+
if (this.props.marked.disabled) {
62+
defaultStyle.textStyle.color = this.theme.textDisabledColor;
63+
}
64+
const resultStyle = (marking.periods || []).reduce((prev, next) => {
6265
if (next.quickAction) {
6366
if (next.first || next.last) {
6467
prev.containerStyle = this.style.firstQuickAction;
@@ -101,7 +104,8 @@ class Day extends Component {
101104
prev.textStyle.color = next.textColor;
102105
}
103106
return prev;
104-
}, {});
107+
}, defaultStyle);
108+
return resultStyle;
105109
}
106110

107111
render() {

src/calendar/day/interactive/style.js renamed to src/calendar/day/period/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {StyleSheet} from 'react-native';
22
import * as defaultStyle from '../../../style';
33

4-
const STYLESHEET_ID = 'stylesheet.day.interactive';
4+
const STYLESHEET_ID = 'stylesheet.day.period';
55

66
const FILLER_HEIGHT = 34;
77

src/calendar/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dateutils from '../dateutils';
1010
import {xdateToData, parseDate} from '../interface';
1111
import styleConstructor from './style';
1212
import Day from './day/basic';
13-
import UnitDay from './day/interactive';
13+
import UnitDay from './day/period';
1414
import MultiDotDay from './day/multi-dot';
1515
import CalendarHeader from './header';
1616
import shouldComponentUpdate from './updater';
@@ -39,7 +39,7 @@ class Calendar extends Component {
3939
// If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday.
4040
firstDay: PropTypes.number,
4141

42-
// Date marking style [simple/interactive]. Default = 'simple'
42+
// Date marking style [simple/period]. Default = 'simple'
4343
markingType: PropTypes.string,
4444

4545
// Hide month navigation arrows. Default = false
@@ -146,7 +146,7 @@ class Calendar extends Component {
146146
}
147147
let dayComp;
148148
if (!dateutils.sameMonth(day, this.state.currentMonth) && this.props.hideExtraDays) {
149-
if (this.props.markingType === 'interactive') {
149+
if (this.props.markingType === 'period') {
150150
dayComp = (<View key={id} style={{flex: 1}}/>);
151151
} else {
152152
dayComp = (<View key={id} style={{width: 32}}/>);
@@ -171,7 +171,7 @@ class Calendar extends Component {
171171

172172
getDayComponent() {
173173
switch (this.props.markingType) {
174-
case 'interactive':
174+
case 'period':
175175
return UnitDay;
176176
case 'multi-dot':
177177
return MultiDotDay;

0 commit comments

Comments
 (0)