Skip to content

Commit

Permalink
fix: takeoverTap not work in multi mode
Browse files Browse the repository at this point in the history
  • Loading branch information
付登荣 committed Nov 10, 2019
1 parent 3c8795b commit 44f21f3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
55 changes: 32 additions & 23 deletions calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1704,11 +1704,14 @@
const { gesture: t } = this.data;
if (this.slideLock) {
if (c.isLeft(t, e.touches[0])) {
if ((this.setData({ 'calendar.leftSwipe': 1 }), this.weekMode))
if (
(this.setData({ 'calendar.leftSwipe': 1 }),
(this.currentYM = (0, o.getCurrentYM)()),
this.weekMode)
)
return (
(this.slideLock = !1),
(this.currentDates = (0, o.getCalendarDates)()),
(this.currentYM = (0, o.getCurrentYM)()),
(0, s.default)(this).calculateNextWeekDays(),
this.onSwipeCalendar('next_week'),
void this.onWeekChange('next_week')
Expand All @@ -1718,11 +1721,14 @@
(this.slideLock = !1);
}
if (c.isRight(t, e.touches[0])) {
if ((this.setData({ 'calendar.rightSwipe': 1 }), this.weekMode))
if (
(this.setData({ 'calendar.rightSwipe': 1 }),
(this.currentYM = (0, o.getCurrentYM)()),
this.weekMode)
)
return (
(this.slideLock = !1),
(this.currentDates = (0, o.getCalendarDates)()),
(this.currentYM = (0, o.getCurrentYM)()),
(0, s.default)(this).calculatePrevWeekDays(),
this.onSwipeCalendar('prev_week'),
void this.onWeekChange('prev_week')
Expand All @@ -1737,7 +1743,10 @@
this.setData({ 'calendar.leftSwipe': 0, 'calendar.rightSwipe': 0 });
},
onSwipeCalendar(e) {
this.triggerEvent('onSwipe', { directionType: e });
this.triggerEvent('onSwipe', {
directionType: e,
currentYM: this.currentYM
});
},
onWeekChange(e) {
this.triggerEvent('whenChangeWeek', {
Expand Down Expand Up @@ -1848,31 +1857,31 @@
whenMulitSelect(e) {
(0, d.isComponent)(this) && (i = this);
const { calendar: t = {} } = D(),
{ days: a, todoLabels: n } = t;
let { selectedDay: s = [] } = t;
const r = a[e];
if (r) {
if (((r.choosed = !r.choosed), r.choosed)) {
r.cancel = !1;
{ days: a, todoLabels: n } = t,
s = (0, l.default)(i).getCalendarConfig();
let { selectedDay: r = [] } = t;
const o = a[e];
if (o) {
if (((o.choosed = !o.choosed), o.choosed)) {
o.cancel = !1;
const { showLabelAlways: e } = D('calendar');
e && r.showTodoLabel
? (r.showTodoLabel = !0)
: (r.showTodoLabel = !1),
s.push(r);
e && o.showTodoLabel
? (o.showTodoLabel = !0)
: (o.showTodoLabel = !1),
s.takeoverTap || r.push(o);
} else {
r.cancel = !0;
const e = `${r.year}-${r.month}-${r.day}`;
(s = s.filter(t => e !== `${t.year}-${t.month}-${t.day}`)),
o.cancel = !0;
const e = `${o.year}-${o.month}-${o.day}`;
(r = r.filter(t => e !== `${t.year}-${t.month}-${t.day}`)),
n &&
n.forEach(t => {
e === `${t.year}-${t.month}-${t.day}` &&
(r.showTodoLabel = !0);
(o.showTodoLabel = !0);
});
}
if ((0, l.default)(i).getCalendarConfig().takeoverTap)
return i.triggerEvent('onTapDay', r);
g({ 'calendar.days': a, 'calendar.selectedDay': s }),
p.afterTapDay(r, s);
if (s.takeoverTap) return i.triggerEvent('onTapDay', o);
g({ 'calendar.days': a, 'calendar.selectedDay': r }),
p.afterTapDay(o, r);
}
},
whenSingleSelect(e) {
Expand Down
7 changes: 4 additions & 3 deletions src/component/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ Component({
this.setData({
'calendar.leftSwipe': 1
});
this.currentYM = getCurrentYM();
if (this.weekMode) {
this.slideLock = false;
this.currentDates = getCalendarDates();
this.currentYM = getCurrentYM();
Week(this).calculateNextWeekDays();
this.onSwipeCalendar('next_week');
this.onWeekChange('next_week');
Expand All @@ -180,10 +180,10 @@ Component({
this.setData({
'calendar.rightSwipe': 1
});
this.currentYM = getCurrentYM();
if (this.weekMode) {
this.slideLock = false;
this.currentDates = getCalendarDates();
this.currentYM = getCurrentYM();
Week(this).calculatePrevWeekDays();
this.onSwipeCalendar('prev_week');
this.onWeekChange('prev_week');
Expand All @@ -202,7 +202,8 @@ Component({
},
onSwipeCalendar(direction) {
this.triggerEvent('onSwipe', {
directionType: direction
directionType: direction,
currentYM: this.currentYM
});
},
onWeekChange(direction) {
Expand Down
6 changes: 4 additions & 2 deletions src/component/calendar/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const conf = {
if (isComponent(this)) Component = this;
const { calendar = {} } = getData();
const { days, todoLabels } = calendar;
const config = CalendarConfig(Component).getCalendarConfig();
let { selectedDay: selectedDays = [] } = calendar;
const currentDay = days[dateIdx];
if (!currentDay) return;
Expand Down Expand Up @@ -123,9 +124,10 @@ const conf = {
} else {
currentDay.showTodoLabel = false;
}
selectedDays.push(currentDay);
if (!config.takeoverTap) {
selectedDays.push(currentDay);
}
}
const config = CalendarConfig(Component).getCalendarConfig();
if (config.takeoverTap) {
return Component.triggerEvent('onTapDay', currentDay);
}
Expand Down
2 changes: 1 addition & 1 deletion test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
delRepeatedEnableDay,
convertEnableAreaToTimestamp,
converEnableDaysToTimestamp
} from '../src/component/calendar/utils';
} from '../src/component/calendar/func/utils';

test('unique days array by date', () => {
expect(uniqueArrayByDate(mock.Days)).toEqual(mock.UniqueArrayByDate.Expected);
Expand Down

0 comments on commit 44f21f3

Please sign in to comment.