Merge branch 'dev' into next
This commit is contained in:
+14
-13
@@ -1,5 +1,6 @@
|
||||
// Utils
|
||||
import { pick } from '../utils';
|
||||
import { raf } from '../utils/dom/raf';
|
||||
import { isDate } from '../utils/validate/date';
|
||||
import { getScrollTop } from '../utils/dom/scroll';
|
||||
import {
|
||||
@@ -191,13 +192,13 @@ export default createComponent({
|
||||
this.$refs.body.getBoundingClientRect().height
|
||||
);
|
||||
this.onScroll();
|
||||
this.scrollIntoView();
|
||||
});
|
||||
this.scrollIntoView();
|
||||
},
|
||||
|
||||
// scroll to current month
|
||||
scrollIntoView() {
|
||||
this.$nextTick(() => {
|
||||
raf(() => {
|
||||
const { currentDate } = this;
|
||||
|
||||
if (!currentDate) {
|
||||
@@ -258,31 +259,27 @@ export default createComponent({
|
||||
const { body } = this.$refs;
|
||||
const { months, monthRefs } = this;
|
||||
const top = getScrollTop(body);
|
||||
const bottom = top + this.bodyHeight;
|
||||
|
||||
const heights = months.map(
|
||||
(item, index) => monthRefs[index].height.value
|
||||
);
|
||||
const heightSum = heights.reduce((a, b) => a + b, 0);
|
||||
|
||||
// iOS scroll bounce may exceed the range
|
||||
let bottom = top + this.bodyHeight;
|
||||
if (bottom > heightSum && top > 0) {
|
||||
bottom = heightSum;
|
||||
return;
|
||||
}
|
||||
|
||||
let height = 0;
|
||||
let currentMonth;
|
||||
|
||||
// add offset to avoid rem accuracy issues
|
||||
// see: https://github.com/youzan/vant/issues/6929
|
||||
const viewportOffset = 50;
|
||||
const viewportTop = top - viewportOffset;
|
||||
const viewportBottom = bottom + viewportOffset;
|
||||
let visibleIndex;
|
||||
|
||||
for (let i = 0; i < months.length; i++) {
|
||||
const visible =
|
||||
height <= viewportBottom && height + heights[i] >= viewportTop;
|
||||
const visible = height <= bottom && height + heights[i] >= top;
|
||||
|
||||
if (visible && !currentMonth) {
|
||||
visibleIndex = i;
|
||||
currentMonth = monthRefs[i];
|
||||
}
|
||||
|
||||
@@ -293,10 +290,14 @@ export default createComponent({
|
||||
});
|
||||
}
|
||||
|
||||
monthRefs[i].setVisible(visible);
|
||||
height += heights[i];
|
||||
}
|
||||
|
||||
months.forEach((month, index) => {
|
||||
const visible = index >= visibleIndex - 1 && index <= visibleIndex + 1;
|
||||
monthRefs[index].setVisible(visible);
|
||||
});
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (currentMonth) {
|
||||
this.subtitle = currentMonth.getTitle();
|
||||
|
||||
Reference in New Issue
Block a user