Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit 6e80ff6

Browse files
authored
SP-41 refactor: 일, 주 변경 시 날짜 설정 (#14)
1 parent caa902a commit 6e80ff6

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@payhereinc/react-native-week-view",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"description": "Week View Calendar for React Native",
55
"main": "index.js",
66
"repository": {

src/WeekView/WeekView.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export default class WeekView extends Component {
4141
this.eventsGridScrollX = new Animated.Value(0);
4242

4343
const initialDates = this.calculatePagesDates(
44-
props.selectedDate,
44+
moment(props.selectedDate).month() === moment().month()
45+
? moment().toDate()
46+
: props.selectedDate,
4547
props.numberOfDays,
4648
props.weekStartsOn,
4749
props.prependMostRecent,
@@ -70,8 +72,20 @@ export default class WeekView extends Component {
7072
setLocale(this.props.locale);
7173
}
7274
if (this.props.numberOfDays !== prevProps.numberOfDays) {
75+
const prevMonth =
76+
prevProps.numberOfDays === 7
77+
? moment(this.state.currentMoment).endOf('week').month()
78+
: moment(this.state.currentMoment).month();
79+
const currentMoment =
80+
moment().month() !== prevMonth
81+
? moment(this.state.currentMoment)
82+
.endOf('week')
83+
.startOf('month')
84+
.toDate()
85+
: moment().toDate();
86+
7387
const initialDates = this.calculatePagesDates(
74-
this.state.currentMoment,
88+
currentMoment,
7589
this.props.numberOfDays,
7690
this.props.weekStartsOn,
7791
this.props.prependMostRecent,
@@ -320,7 +334,7 @@ export default class WeekView extends Component {
320334
) => {
321335
const initialDates = [];
322336
const centralDate = moment(currentMoment);
323-
if (numberOfDays === 7 || fixedHorizontally) {
337+
if (numberOfDays !== 1 && (numberOfDays === 7 || fixedHorizontally)) {
324338
centralDate.subtract(
325339
// Ensure centralDate is before currentMoment
326340
(centralDate.day() + 7 - weekStartsOn) % 7,

0 commit comments

Comments
 (0)