mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00
refactor(backdrop): place disable-scroll class on ion-app
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { Directive, ElementRef, Input } from '@angular/core';
|
||||
import { Directive, Input } from '@angular/core';
|
||||
|
||||
import { isTrueProperty} from '../../util/util';
|
||||
import { nativeRaf} from '../../util/dom';
|
||||
import { AppRoot } from '../app/app';
|
||||
import { isTrueProperty } from '../../util/util';
|
||||
|
||||
const DISABLE_SCROLL = 'disable-scroll';
|
||||
|
||||
@ -19,25 +19,19 @@ const DISABLE_SCROLL = 'disable-scroll';
|
||||
export class Backdrop {
|
||||
private static nuBackDrops: number = 0;
|
||||
|
||||
private static push() {
|
||||
private static push(appRoot: AppRoot) {
|
||||
if (this.nuBackDrops === 0) {
|
||||
nativeRaf(() => {
|
||||
console.debug('adding .disable-scroll to body');
|
||||
document.body.classList.add(DISABLE_SCROLL);
|
||||
});
|
||||
appRoot.disableScroll = true;
|
||||
}
|
||||
this.nuBackDrops++;
|
||||
}
|
||||
|
||||
private static pop() {
|
||||
private static pop(appRoot: AppRoot) {
|
||||
if (this.nuBackDrops > 0) {
|
||||
this.nuBackDrops--;
|
||||
|
||||
if (this.nuBackDrops === 0) {
|
||||
nativeRaf(() => {
|
||||
console.debug('removing .disable-scroll from body');
|
||||
document.body.classList.remove(DISABLE_SCROLL);
|
||||
});
|
||||
appRoot.disableScroll = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,18 +39,18 @@ export class Backdrop {
|
||||
private pushed: boolean = false;
|
||||
@Input() disableScroll = true;
|
||||
|
||||
constructor(public elementRef: ElementRef) {}
|
||||
constructor(private _appRoot: AppRoot) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (isTrueProperty(this.disableScroll)) {
|
||||
Backdrop.push();
|
||||
Backdrop.push(this._appRoot);
|
||||
this.pushed = true;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.pushed) {
|
||||
Backdrop.pop();
|
||||
Backdrop.pop(this._appRoot);
|
||||
this.pushed = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user