refactor(Popup): create overlay for every popup (#6357)

This commit is contained in:
neverland
2020-05-24 16:24:20 +08:00
committed by GitHub
parent 6a2a0cc5c6
commit c5c2e9690d
5 changed files with 61 additions and 83 deletions
+20 -8
View File
@@ -1,6 +1,11 @@
// Context
import { context } from './context';
import { openOverlay, closeOverlay, updateOverlay } from './overlay';
import {
openOverlay,
closeOverlay,
updateOverlay,
removeOverlay,
} from './overlay';
// Utils
import { on, off, preventDefault } from '../../utils/dom/event';
@@ -94,7 +99,8 @@ export function PopupMixin(options = {}) {
},
beforeDestroy() {
this.close();
this.removeLock();
removeOverlay(this);
if (this.getContainer) {
removeNode(this.$el);
@@ -123,7 +129,10 @@ export function PopupMixin(options = {}) {
this.opened = true;
this.renderOverlay();
this.addLock();
},
addLock() {
if (this.lockScroll) {
on(document, 'touchstart', this.touchStart);
on(document, 'touchmove', this.onTouchMove);
@@ -135,11 +144,7 @@ export function PopupMixin(options = {}) {
}
},
close() {
if (!this.opened) {
return;
}
removeLock() {
if (this.lockScroll) {
context.lockCount--;
off(document, 'touchstart', this.touchStart);
@@ -149,9 +154,16 @@ export function PopupMixin(options = {}) {
document.body.classList.remove('van-overflow-hidden');
}
}
},
close() {
if (!this.opened) {
return;
}
this.opened = false;
closeOverlay(this);
this.opened = false;
this.removeLock();
this.$emit('input', false);
},