From 32b0b16cb88b680dcdb6cdb4df255ba6d0920403 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 18 Apr 2020 10:15:52 +0800 Subject: [PATCH] fix(Swipe): incorrect width after resize if hidden (#6084) --- .../test/__snapshots__/index.spec.js.snap | 10 +++++----- src/swipe/index.js | 17 +++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/image-preview/test/__snapshots__/index.spec.js.snap b/src/image-preview/test/__snapshots__/index.spec.js.snap index 5ac20fc5b..b4c5692e2 100644 --- a/src/image-preview/test/__snapshots__/index.spec.js.snap +++ b/src/image-preview/test/__snapshots__/index.spec.js.snap @@ -4,7 +4,7 @@ exports[`close-icon prop 1`] = `
-
+
1 / 0
@@ -14,7 +14,7 @@ exports[`close-icon-position prop 1`] = `
-
+
1 / 0
@@ -23,7 +23,7 @@ exports[`close-icon-position prop 1`] = ` exports[`cover slot 1`] = `
-
+
1 / 0
Custom Cover Content
@@ -33,7 +33,7 @@ exports[`cover slot 1`] = ` exports[`index slot 1`] = `
-
+
Custom Index
@@ -55,7 +55,7 @@ exports[`render image 1`] = ` exports[`set show-index prop to false 1`] = `
-
+
`; diff --git a/src/swipe/index.js b/src/swipe/index.js index 01873c39d..95816beea 100644 --- a/src/swipe/index.js +++ b/src/swipe/index.js @@ -149,31 +149,25 @@ export default createComponent({ }, mounted() { - this.initRect(); this.bindTouchEvent(this.$refs.track); }, methods: { - initRect() { - this.rect = this.$el.getBoundingClientRect(); - }, - // initialize swipe position initialize(active = +this.initialSwipe) { - if (!this.rect) { + if (!this.$el || isHidden(this.$el)) { return; } clearTimeout(this.timer); - if (this.$el && !isHidden(this.$el)) { - const { rect } = this; - this.computedWidth = Math.round(+this.width || rect.width); - this.computedHeight = Math.round(+this.height || rect.height); - } + const rect = this.$el.getBoundingClientRect(); + this.rect = rect; this.swiping = true; this.active = active; + this.computedWidth = Math.round(+this.width || rect.width); + this.computedHeight = Math.round(+this.height || rect.height); this.offset = this.getTargetOffset(active); this.children.forEach((swipe) => { swipe.offset = 0; @@ -183,7 +177,6 @@ export default createComponent({ // @exposed-api resize() { - this.initRect(); this.initialize(this.activeIndicator); },