mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
fix(Sticky): pageScroll bind page (#3092)
* fix(Sticky): pageScroll miss this * fix(Sticky): pageScroll miss this
This commit is contained in:
parent
90b3aae5b2
commit
ac6b34a823
@ -27,7 +27,10 @@ export const pageScrollMixin = (scroller: Scroller) =>
|
|||||||
if (Array.isArray(page.vanPageScroller)) {
|
if (Array.isArray(page.vanPageScroller)) {
|
||||||
page.vanPageScroller.push(scroller.bind(this));
|
page.vanPageScroller.push(scroller.bind(this));
|
||||||
} else {
|
} else {
|
||||||
page.vanPageScroller = [page.onPageScroll, scroller.bind(this)];
|
page.vanPageScroller = [
|
||||||
|
page.onPageScroll.bind(page),
|
||||||
|
scroller.bind(this)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
page.onPageScroll = onPageScroll;
|
page.onPageScroll = onPageScroll;
|
||||||
@ -36,7 +39,7 @@ export const pageScrollMixin = (scroller: Scroller) =>
|
|||||||
detached() {
|
detached() {
|
||||||
const page = getCurrentPage();
|
const page = getCurrentPage();
|
||||||
page.vanPageScroller = (page.vanPageScroller || []).filter(
|
page.vanPageScroller = (page.vanPageScroller || []).filter(
|
||||||
(item) => item !== scroller
|
item => item !== scroller
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
@ -26,13 +26,13 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.updateTabs();
|
this.updateTabs();
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
color: {
|
color: {
|
||||||
type: String,
|
type: String,
|
||||||
observer: 'setLine',
|
observer: 'setLine'
|
||||||
},
|
},
|
||||||
sticky: Boolean,
|
sticky: Boolean,
|
||||||
animated: {
|
animated: {
|
||||||
@ -41,18 +41,18 @@ VantComponent({
|
|||||||
this.children.forEach((child: TrivialInstance, index: number) =>
|
this.children.forEach((child: TrivialInstance, index: number) =>
|
||||||
child.updateRender(index === this.data.currentIndex, this)
|
child.updateRender(index === this.data.currentIndex, this)
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
swipeable: Boolean,
|
swipeable: Boolean,
|
||||||
lineWidth: {
|
lineWidth: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
value: -1,
|
value: -1,
|
||||||
observer: 'setLine',
|
observer: 'setLine'
|
||||||
},
|
},
|
||||||
lineHeight: {
|
lineHeight: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
value: -1,
|
value: -1,
|
||||||
observer: 'setLine',
|
observer: 'setLine'
|
||||||
},
|
},
|
||||||
titleActiveColor: String,
|
titleActiveColor: String,
|
||||||
titleInactiveColor: String,
|
titleInactiveColor: String,
|
||||||
@ -63,45 +63,45 @@ VantComponent({
|
|||||||
if (name !== this.getCurrentName()) {
|
if (name !== this.getCurrentName()) {
|
||||||
this.setCurrentIndexByName(name);
|
this.setCurrentIndexByName(name);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
value: 'line',
|
value: 'line'
|
||||||
},
|
},
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true
|
||||||
},
|
},
|
||||||
ellipsis: {
|
ellipsis: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true
|
||||||
},
|
},
|
||||||
duration: {
|
duration: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 0.3,
|
value: 0.3
|
||||||
},
|
},
|
||||||
zIndex: {
|
zIndex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 1,
|
value: 1
|
||||||
},
|
},
|
||||||
swipeThreshold: {
|
swipeThreshold: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 4,
|
value: 4,
|
||||||
observer(value) {
|
observer(value) {
|
||||||
this.setData({
|
this.setData({
|
||||||
scrollable: this.children.length > value || !this.data.ellipsis,
|
scrollable: this.children.length > value || !this.data.ellipsis
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
offsetTop: {
|
offsetTop: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 0,
|
value: 0
|
||||||
},
|
},
|
||||||
lazyRender: {
|
lazyRender: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true,
|
value: true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
@ -111,7 +111,7 @@ VantComponent({
|
|||||||
scrollable: false,
|
scrollable: false,
|
||||||
trackStyle: '',
|
trackStyle: '',
|
||||||
currentIndex: null,
|
currentIndex: null,
|
||||||
container: null,
|
container: null
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -124,7 +124,7 @@ VantComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
updateContainer() {
|
updateContainer() {
|
||||||
this.setData({
|
this.setData({
|
||||||
container: () => this.createSelectorQuery().select('.van-tabs'),
|
container: () => this.createSelectorQuery().select('.van-tabs')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -132,8 +132,7 @@ VantComponent({
|
|||||||
const { children = [], data } = this;
|
const { children = [], data } = this;
|
||||||
this.setData({
|
this.setData({
|
||||||
tabs: children.map((child: TrivialInstance) => child.data),
|
tabs: children.map((child: TrivialInstance) => child.data),
|
||||||
scrollable:
|
scrollable: this.children.length > data.swipeThreshold || !data.ellipsis
|
||||||
this.children.length > data.swipeThreshold || !data.ellipsis,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setCurrentIndexByName(this.getCurrentName() || data.active);
|
this.setCurrentIndexByName(this.getCurrentName() || data.active);
|
||||||
@ -151,7 +150,7 @@ VantComponent({
|
|||||||
this.$emit(eventName, {
|
this.$emit(eventName, {
|
||||||
index: currentChild.index,
|
index: currentChild.index,
|
||||||
name: currentChild.getComputedName(),
|
name: currentChild.getComputedName(),
|
||||||
title: currentChild.data.title,
|
title: currentChild.data.title
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -236,7 +235,7 @@ VantComponent({
|
|||||||
duration,
|
duration,
|
||||||
currentIndex,
|
currentIndex,
|
||||||
lineWidth,
|
lineWidth,
|
||||||
lineHeight,
|
lineHeight
|
||||||
} = this.data;
|
} = this.data;
|
||||||
|
|
||||||
this.getRect('.van-tab', true).then(
|
this.getRect('.van-tab', true).then(
|
||||||
@ -271,7 +270,7 @@ VantComponent({
|
|||||||
-webkit-transform: translateX(${left}px);
|
-webkit-transform: translateX(${left}px);
|
||||||
transform: translateX(${left}px);
|
transform: translateX(${left}px);
|
||||||
${transition}
|
${transition}
|
||||||
`,
|
`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -287,7 +286,7 @@ VantComponent({
|
|||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
this.getRect('.van-tab', true),
|
this.getRect('.van-tab', true),
|
||||||
this.getRect('.van-tabs__nav'),
|
this.getRect('.van-tabs__nav')
|
||||||
]).then(
|
]).then(
|
||||||
([tabRects, navRect]: [
|
([tabRects, navRect]: [
|
||||||
WechatMiniprogram.BoundingClientRectCallbackResult[],
|
WechatMiniprogram.BoundingClientRectCallbackResult[],
|
||||||
@ -299,7 +298,7 @@ VantComponent({
|
|||||||
.reduce((prev, curr) => prev + curr.width, 0);
|
.reduce((prev, curr) => prev + curr.width, 0);
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2,
|
scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -336,6 +335,6 @@ VantComponent({
|
|||||||
this.setCurrentIndex(currentIndex + 1);
|
this.setCurrentIndex(currentIndex + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user