Skip to content

Commit b877903

Browse files
committed
Add prop updateWeek.
Controls whether the week view should update when other props change.
1 parent 2520376 commit b877903

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ This is the list of all the props you can pass to the component so that you can
9898
* selectedDate: PropTypes.any - Date to be used as pre selected Date. It is internaly wrapped by `moment` so it accepts both `Date` and `moment Date`.
9999
* onDateSelected: PropTypes.func - Function to be used as a callback when a date is selected. It returns `moment Date`
100100
* onWeekChanged: PropTypes.func - Function to be used as a callback when a week is changed. It returns `moment Date`
101+
* updateWeek: PropTypes.bool - (default true) Update the week view if other props change. If `false`, the week view won't change when other props change, but will still respond to left/right selectors.
101102
* useIsoWeekday: PropTypes.bool - start week on ISO day of week (default true). If false, starts week on _startingDate_ parameter.
102103
* minDate: PropTypes.any - minimum date that the calendar may navigate to. A week is allowed if minDate falls within the current week.
103104
* maxDate: PropTypes.any - maximum date that the calendar may navigate to. A week is allowed if maxDate falls within the current week.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-calendar-strip",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Easy to use and visually stunning calendar component for React Native",
55
"main": "index.js",
66
"directories": {

src/CalendarStrip.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class CalendarStrip extends Component {
2727
selectedDate: PropTypes.any,
2828
onDateSelected: PropTypes.func,
2929
onWeekChanged: PropTypes.func,
30+
updateWeek: PropTypes.bool,
3031
useIsoWeekday: PropTypes.bool,
3132
minDate: PropTypes.any,
3233
maxDate: PropTypes.any,
@@ -77,6 +78,7 @@ export default class CalendarStrip extends Component {
7778
useIsoWeekday: true,
7879
showMonth: true,
7980
showDate: true,
81+
updateWeek: true,
8082
iconLeft: require("./img/left-arrow-black.png"),
8183
iconRight: require("./img/right-arrow-black.png"),
8284
calendarHeaderFormat: "MMMM YYYY",
@@ -182,7 +184,7 @@ export default class CalendarStrip extends Component {
182184
updateState = true;
183185
// No need to update week start here
184186
startingDate = {
185-
startingDate: this.setLocale(moment(nextProps.startingDate))
187+
startingDate: this.updateWeekStart(nextProps.startingDate)
186188
};
187189
weekData = this.updateWeekData(
188190
startingDate.startingDate,
@@ -273,6 +275,9 @@ export default class CalendarStrip extends Component {
273275
// Set the current visible week to the selectedDate
274276
// When date param is undefined, an update always occurs (e.g. initialize)
275277
updateWeekStart(newStartDate, originalStartDate = this.state.startingDate) {
278+
if (!this.props.updateWeek) {
279+
return originalStartDate;
280+
}
276281
let startingDate = moment(newStartDate).startOf("day");
277282
let daysDiff = startingDate.diff(originalStartDate.startOf("day"), "days");
278283
if (daysDiff === 0) {
@@ -285,7 +290,7 @@ export default class CalendarStrip extends Component {
285290
: Math.ceil(Math.abs(adjustWeeks));
286291
startingDate = originalStartDate[addOrSubtract](adjustWeeks, "w");
287292

288-
return startingDate;
293+
return this.setLocale(startingDate);
289294
}
290295

291296
// Get & update week states for the week based on the startingDate

0 commit comments

Comments
 (0)