mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
@ -1,5 +1,6 @@
|
||||
import { Component, ComponentInterface, Event, EventEmitter, Listen, Prop } from '@stencil/core';
|
||||
|
||||
import { GESTURE_CONTROLLER } from '../../utils/gesture/gesture-controller';
|
||||
import { now } from '../../utils/helpers';
|
||||
|
||||
@Component({
|
||||
@ -13,6 +14,9 @@ import { now } from '../../utils/helpers';
|
||||
export class Backdrop implements ComponentInterface {
|
||||
|
||||
private lastClick = -10000;
|
||||
private blocker = GESTURE_CONTROLLER.createBlocker({
|
||||
disableScroll: true
|
||||
});
|
||||
|
||||
@Prop({ context: 'document' }) doc!: Document;
|
||||
|
||||
@ -37,11 +41,13 @@ export class Backdrop implements ComponentInterface {
|
||||
@Event() ionBackdropTap!: EventEmitter<void>;
|
||||
|
||||
componentDidLoad() {
|
||||
registerBackdrop(this.doc, this);
|
||||
if (this.stopPropagation) {
|
||||
this.blocker.block();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUnload() {
|
||||
unregisterBackdrop(this.doc, this);
|
||||
this.blocker.destroy();
|
||||
}
|
||||
|
||||
@Listen('touchstart', { passive: false, capture: true })
|
||||
@ -78,18 +84,3 @@ export class Backdrop implements ComponentInterface {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const BACKDROP_NO_SCROLL = 'backdrop-no-scroll';
|
||||
const activeBackdrops = new Set();
|
||||
|
||||
function registerBackdrop(doc: Document, backdrop: any) {
|
||||
activeBackdrops.add(backdrop);
|
||||
doc.body.classList.add(BACKDROP_NO_SCROLL);
|
||||
}
|
||||
|
||||
function unregisterBackdrop(doc: Document, backdrop: any) {
|
||||
activeBackdrops.delete(backdrop);
|
||||
if (activeBackdrops.size === 0) {
|
||||
doc.body.classList.remove(BACKDROP_NO_SCROLL);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user