fix(Tab): swipe multi index with double refers (#4539)

* fix(Tab): swipe multi index with double refers

* fix(Tab): adjust swiping
This commit is contained in:
nemo-shen 2021-09-30 10:22:50 +08:00 committed by GitHub
parent 04ddd811b2
commit 7cbf287438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,7 +94,7 @@ VantComponent({
scrollLeft: 0, scrollLeft: 0,
scrollable: false, scrollable: false,
currentIndex: 0, currentIndex: 0,
container: (null as unknown) as () => WechatMiniprogram.NodesRef, container: null as unknown as () => WechatMiniprogram.NodesRef,
skipTransition: true, skipTransition: true,
scrollWithAnimation: false, scrollWithAnimation: false,
lineOffsetLeft: 0, lineOffsetLeft: 0,
@ -102,6 +102,7 @@ VantComponent({
mounted() { mounted() {
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.swiping = true;
this.setData({ this.setData({
container: () => this.createSelectorQuery().select('.van-tabs'), container: () => this.createSelectorQuery().select('.van-tabs'),
}); });
@ -238,6 +239,7 @@ VantComponent({
(rect.width - lineRect.width) / 2 + (ellipsis ? 0 : 8); (rect.width - lineRect.width) / 2 + (ellipsis ? 0 : 8);
this.setData({ lineOffsetLeft }); this.setData({ lineOffsetLeft });
this.swiping = true;
if (skipTransition) { if (skipTransition) {
nextTick(() => { nextTick(() => {
@ -287,14 +289,14 @@ VantComponent({
}, },
onTouchMove(event: WechatMiniprogram.TouchEvent) { onTouchMove(event: WechatMiniprogram.TouchEvent) {
if (!this.data.swipeable) return; if (!this.data.swipeable || !this.swiping) return;
this.touchMove(event); this.touchMove(event);
}, },
// watch swipe touch end // watch swipe touch end
onTouchEnd() { onTouchEnd() {
if (!this.data.swipeable) return; if (!this.data.swipeable || !this.swiping) return;
const { direction, deltaX, offsetX } = this; const { direction, deltaX, offsetX } = this;
const minSwipeDistance = 50; const minSwipeDistance = 50;
@ -305,6 +307,8 @@ VantComponent({
this.setCurrentIndex(index); this.setCurrentIndex(index);
} }
} }
this.swiping = false;
}, },
getAvaiableTab(direction: number) { getAvaiableTab(direction: number) {