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

Commit

Permalink
SP-41 refactor: 일, 주 변경 시 날짜 설정 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarinduk authored Mar 2, 2022
1 parent caa902a commit 6e80ff6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@payhereinc/react-native-week-view",
"version": "0.6.7",
"version": "0.6.8",
"description": "Week View Calendar for React Native",
"main": "index.js",
"repository": {
Expand Down
20 changes: 17 additions & 3 deletions src/WeekView/WeekView.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export default class WeekView extends Component {
this.eventsGridScrollX = new Animated.Value(0);

const initialDates = this.calculatePagesDates(
props.selectedDate,
moment(props.selectedDate).month() === moment().month()
? moment().toDate()
: props.selectedDate,
props.numberOfDays,
props.weekStartsOn,
props.prependMostRecent,
Expand Down Expand Up @@ -70,8 +72,20 @@ export default class WeekView extends Component {
setLocale(this.props.locale);
}
if (this.props.numberOfDays !== prevProps.numberOfDays) {
const prevMonth =
prevProps.numberOfDays === 7
? moment(this.state.currentMoment).endOf('week').month()
: moment(this.state.currentMoment).month();
const currentMoment =
moment().month() !== prevMonth
? moment(this.state.currentMoment)
.endOf('week')
.startOf('month')
.toDate()
: moment().toDate();

const initialDates = this.calculatePagesDates(
this.state.currentMoment,
currentMoment,
this.props.numberOfDays,
this.props.weekStartsOn,
this.props.prependMostRecent,
Expand Down Expand Up @@ -320,7 +334,7 @@ export default class WeekView extends Component {
) => {
const initialDates = [];
const centralDate = moment(currentMoment);
if (numberOfDays === 7 || fixedHorizontally) {
if (numberOfDays !== 1 && (numberOfDays === 7 || fixedHorizontally)) {
centralDate.subtract(
// Ensure centralDate is before currentMoment
(centralDate.day() + 7 - weekStartsOn) % 7,
Expand Down

0 comments on commit 6e80ff6

Please sign in to comment.