diff --git a/packages/dialog/index.ts b/packages/dialog/index.ts index 5ec1628ec..24248d5c3 100644 --- a/packages/dialog/index.ts +++ b/packages/dialog/index.ts @@ -98,17 +98,22 @@ VantComponent({ this.close('overlay'); }, - close(action) { + close(action: string) { this.setData({ show: false }); - wx.nextTick(() => { - this.$emit('close', action); + this.closeAction = action; + }, - const { callback } = this.data; - if (callback) { - callback(action, this); - } - }); + onAfterLeave() { + const { closeAction: action } = this; + + this.$emit('close', action); + + const { callback } = this.data; + + if (callback) { + callback(action, this); + } }, stopLoading() { diff --git a/packages/dialog/index.wxml b/packages/dialog/index.wxml index a1d8e3cfc..99a6264cd 100644 --- a/packages/dialog/index.wxml +++ b/packages/dialog/index.wxml @@ -11,6 +11,7 @@ close-on-click-overlay="{{ closeOnClickOverlay }}" root-portal="{{ rootPortal }}" bind:close="onClickOverlay" + bind:after-leave="onAfterLeave" > { - const { duration, name } = this.data; - const classNames = getClassNames(name); - const currentDuration = isObj(duration) ? duration.enter : duration; + enureEnter() { + if (this.enterPromise) return; - if (this.status === 'enter') { + this.enterPromise = new Promise((resolve) => this.enter(resolve)); + }, + + enureLeave() { + const { enterPromise } = this; + + if (!enterPromise) return; + + enterPromise + .then(() => new Promise((resolve) => this.leave(resolve))) + .then(() => { + this.enterPromise = null; + }); + }, + + enter(resolve: () => void) { + const { duration, name } = this.data; + const classNames = getClassNames(name); + const currentDuration = isObj(duration) ? duration.enter : duration; + + if (this.status === 'enter') { + return; + } + + this.status = 'enter'; + this.$emit('before-enter'); + + requestAnimationFrame(() => { + if (this.status !== 'enter') { return; } - this.status = 'enter'; - this.$emit('before-enter'); + this.$emit('enter'); + + this.setData({ + inited: true, + display: true, + classes: classNames.enter, + currentDuration, + }); requestAnimationFrame(() => { if (this.status !== 'enter') { return; } - this.$emit('enter'); - - this.setData({ - inited: true, - display: true, - classes: classNames.enter, - currentDuration, - }); - - requestAnimationFrame(() => { - if (this.status !== 'enter') { - return; - } - - this.transitionEnded = false; - this.setData({ classes: classNames['enter-to'] }); - resolve(); - }); + this.transitionEnded = false; + this.setData({ classes: classNames['enter-to'] }); + resolve(); }); }); }, - leave() { - if (!this.enterFinishedPromise) return; - this.enterFinishedPromise.then(() => { - if (!this.data.display) { + leave(resolve: () => void) { + if (!this.data.display) { + return; + } + + const { duration, name } = this.data; + const classNames = getClassNames(name); + const currentDuration = isObj(duration) ? duration.leave : duration; + + this.status = 'leave'; + this.$emit('before-leave'); + + requestAnimationFrame(() => { + if (this.status !== 'leave') { return; } - const { duration, name } = this.data; - const classNames = getClassNames(name); - const currentDuration = isObj(duration) ? duration.leave : duration; + this.$emit('leave'); - this.status = 'leave'; - this.$emit('before-leave'); + this.setData({ + classes: classNames.leave, + currentDuration, + }); requestAnimationFrame(() => { if (this.status !== 'leave') { return; } - this.$emit('leave'); - - this.setData({ - classes: classNames.leave, - currentDuration, - }); - - requestAnimationFrame(() => { - if (this.status !== 'leave') { - return; - } - - this.transitionEnded = false; - setTimeout(() => { - this.onTransitionEnd(); - this.enterFinishedPromise = null; - }, currentDuration); + this.transitionEnded = false; + setTimeout(() => { + this.onTransitionEnd(); + resolve(); + }, currentDuration); - this.setData({ classes: classNames['leave-to'] }); - }); + this.setData({ classes: classNames['leave-to'] }); }); }); }, diff --git a/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap b/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap index 7b99e9bfa..d9db09f65 100644 --- a/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap +++ b/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap @@ -245,6 +245,7 @@ exports[`should render demo and match snapshot 1`] = `