From a54f0af5dd98723bd892c41447ec69c1beebdf86 Mon Sep 17 00:00:00 2001 From: rex Date: Tue, 3 Mar 2020 19:29:21 +0800 Subject: [PATCH] fix(Tab): set container when change active (#2817) fix #2782 --- packages/sticky/index.ts | 17 +++++++++++++++++ packages/tabs/index.ts | 11 ++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/sticky/index.ts b/packages/sticky/index.ts index e2b1d63f..d9b43cea 100644 --- a/packages/sticky/index.ts +++ b/packages/sticky/index.ts @@ -30,6 +30,7 @@ VantComponent({ } this.observeContainer(); + this.updateFixed(); } } }, @@ -63,6 +64,22 @@ VantComponent({ ); }, + updateFixed() { + Promise.all([this.getRect(ROOT_ELEMENT), this.getContainerRect()]).then( + ([ + content, + container + ]: WechatMiniprogram.BoundingClientRectCallbackResult[]) => { + this.setData({ height: content.height }); + this.containerHeight = container.height; + + wx.nextTick(() => { + this.setFixed(content.top); + }); + } + ); + }, + disconnectObserver(observerName?: string) { if (observerName) { const observer: WechatMiniprogram.IntersectionObserver = this[ diff --git a/packages/tabs/index.ts b/packages/tabs/index.ts index c1c07c73..43fa320c 100644 --- a/packages/tabs/index.ts +++ b/packages/tabs/index.ts @@ -114,15 +114,19 @@ VantComponent({ }, mounted() { - this.setData({ - container: () => this.createSelectorQuery().select('.van-tabs') - }, () => { + wx.nextTick(() => { this.setLine(true); this.scrollIntoView(); }); }, methods: { + updateContainer() { + this.setData({ + container: () => this.createSelectorQuery().select('.van-tabs') + }); + }, + updateTabs() { const { children = [], data } = this; this.setData({ @@ -203,6 +207,7 @@ VantComponent({ wx.nextTick(() => { this.setLine(); this.scrollIntoView(); + this.updateContainer(); this.trigger('input'); if (shouldEmitChange) {