Skip to content

Commit 5ebdbf5

Browse files
committed
Removing propTypes duplications and updating 'shouldUpdate'
1 parent b59394d commit 5ebdbf5

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

src/calendar/day/basic/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ import {shouldUpdate} from '../../../component-updater';
66
import styleConstructor from './style';
77
import Marking from '../marking';
88

9+
910
export default class BasicDay extends Component {
1011
static displayName = 'IGNORE';
1112

1213
static propTypes = {
13-
date: PropTypes.object,
14-
state: PropTypes.oneOf(['disabled', 'today', '']),
14+
state: PropTypes.oneOf(['disabled', 'today', '']), //TODO: deprecate
15+
/** The marking object */
1516
marking: PropTypes.any,
16-
markingType: PropTypes.oneOf(Marking.markingTypes),
17+
/** Date marking style [simple/period/multi-dot/multi-period]. Default = 'simple' */
18+
markingType: PropTypes.oneOf(_.values(Marking.markingTypes)),
19+
/** Theme object */
1720
theme: PropTypes.object,
21+
/** onPress callback */
1822
onPress: PropTypes.func,
23+
/** onLongPress callback */
1924
onLongPress: PropTypes.func,
25+
/** The date to return from press callbacks */
26+
date: PropTypes.object,
27+
/** Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates*/
2028
disableAllTouchEventsForDisabledDays: PropTypes.bool
2129
};
2230

@@ -27,7 +35,7 @@ export default class BasicDay extends Component {
2735
}
2836

2937
shouldComponentUpdate(nextProps) {
30-
return shouldUpdate(this.props, nextProps, ['children', 'state', 'marking', 'onPress', 'onLongPress']);
38+
return shouldUpdate(this.props, nextProps, ['children', 'state', 'markingType', 'marking', 'onPress', 'onLongPress', 'date']);
3139
}
3240

3341
onPress = () => {

src/calendar/day/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash';
12
import PropTypes from 'prop-types';
23
import XDate from 'xdate';
34
import React, {Component} from 'react';
@@ -8,24 +9,21 @@ import BasicDay from './basic';
89
import PeriodDay from './period';
910

1011

12+
const basicDayProps = _.omit(BasicDay.propTypes, 'date');
13+
1114
export default class Day extends Component {
1215
static displayName = 'IGNORE';
1316

1417
static propTypes = {
18+
...basicDayProps,
19+
/** The day to render */
1520
day: PropTypes.object,
16-
state: PropTypes.string, // deprecate ???
17-
markingType: PropTypes.string,
18-
marking: PropTypes.any,
19-
theme: PropTypes.object,
20-
onPress: PropTypes.func,
21-
onLongPress: PropTypes.func,
22-
dayComponent: PropTypes.any,
23-
disableAllTouchEventsForDisabledDays: PropTypes.bool,
24-
disabledByDefault: PropTypes.bool
21+
/** Provide custom day rendering component */
22+
dayComponent: PropTypes.any
2523
};
2624

2725
shouldComponentUpdate(nextProps) {
28-
return shouldUpdate(this.props, nextProps, ['day', 'markingType', 'marking', 'onPress', 'onLongPress']);
26+
return shouldUpdate(this.props, nextProps, ['day', 'dayComponent', 'markingType', 'marking', 'onPress', 'onLongPress']);
2927
}
3028

3129
getMarkingLabel() {

src/calendar/day/period/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import styleConstructor from './style';
88
import Dot from '../dot';
99

1010

11-
class Day extends Component {
11+
export default class PeriodDay extends Component {
1212
static displayName = 'IGNORE';
1313

1414
static propTypes = {
15-
// TODO: selected + disabled props should be removed
16-
state: PropTypes.oneOf(['selected', 'disabled', 'today', '']),
17-
theme: PropTypes.object,
15+
state: PropTypes.oneOf(['selected', 'disabled', 'today', '']), //TODO: deprecate
1816
marking: PropTypes.any,
17+
theme: PropTypes.object,
1918
onPress: PropTypes.func,
2019
onLongPress: PropTypes.func,
2120
date: PropTypes.object
@@ -45,7 +44,7 @@ class Day extends Component {
4544
return true;
4645
}
4746

48-
return shouldUpdate(this.props, nextProps, ['state', 'children', 'onPress', 'onLongPress']);
47+
return shouldUpdate(this.props, nextProps, ['children', 'state', 'marking', 'onPress', 'onLongPress', 'date']);
4948
}
5049

5150
getDrawingStyle(marking) {
@@ -215,5 +214,3 @@ class Day extends Component {
215214
);
216215
}
217216
}
218-
219-
export default Day;

src/calendar/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Calendar extends Component {
3030

3131
static propTypes = {
3232
...CalendarHeader.propTypes,
33+
...Day.propTypes,
3334
/** Specify theme properties to override specific styles for calendar parts. Default = {} */
3435
theme: PropTypes.object,
3536
/** Specify style for calendar container element. Default = {} */
@@ -44,8 +45,6 @@ class Calendar extends Component {
4445
firstDay: PropTypes.number,
4546
/** Collection of dates that have to be marked. Default = {} */
4647
markedDates: PropTypes.object,
47-
/** Date marking style [simple/period/multi-dot/multi-period]. Default = 'simple' */
48-
markingType: PropTypes.string,
4948
/** Display loading indicator. Default = false */
5049
displayLoadingIndicator: PropTypes.bool,
5150
/** Show week numbers. Default = false */
@@ -62,16 +61,12 @@ class Calendar extends Component {
6261
onMonthChange: PropTypes.func,
6362
/** Handler which gets executed when visible month changes in calendar. Default = undefined */
6463
onVisibleMonthsChange: PropTypes.func,
65-
/** Provide custom day rendering component */
66-
dayComponent: PropTypes.any,
6764
/** Disables changing month when click on days of other months (when hideExtraDays is false). Default = false */
6865
disableMonthChange: PropTypes.bool,
6966
/** Enable the option to swipe between months. Default: false */
7067
enableSwipeMonths: PropTypes.bool,
7168
/** Disable days by default. Default = false */
7269
disabledByDefault: PropTypes.bool,
73-
/** Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates*/
74-
disableAllTouchEventsForDisabledDays: PropTypes.bool,
7570
/** Style passed to the header */
7671
headerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
7772
/** Allow rendering of a totally custom header */
@@ -223,7 +218,7 @@ class Calendar extends Component {
223218

224219
renderDay(day, id) {
225220
const {hideExtraDays} = this.props;
226-
const dayCompProps = extractComponentProps(Day, this.props);
221+
const dayProps = extractComponentProps(Day, this.props);
227222

228223
if (!dateutils.sameMonth(day, this.state.currentMonth) && hideExtraDays) {
229224
return <View key={id} style={this.style.emptyDayContainer} />;
@@ -232,7 +227,7 @@ class Calendar extends Component {
232227
return (
233228
<View style={this.style.dayContainer} key={id}>
234229
<Day
235-
{...dayCompProps}
230+
{...dayProps}
236231
day={day}
237232
state={this.getState(day)}
238233
marking={this.getDateMarking(day)}

src/expandableCalendar/week.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Week extends Component {
9999

100100
renderDay(day, id) {
101101
const {current, hideExtraDays} = this.props;
102-
const dayCompProps = extractComponentProps(Day, this.props);
102+
const dayProps = extractComponentProps(Day, this.props);
103103

104104
// hide extra days
105105
if (current && hideExtraDays) {
@@ -111,7 +111,7 @@ class Week extends Component {
111111
return (
112112
<View style={this.style.dayContainer} key={id}>
113113
<Day
114-
{...dayCompProps}
114+
{...dayProps}
115115
day={day}
116116
state={this.getState(day)}
117117
marking={this.getDateMarking(day)}

0 commit comments

Comments
 (0)