feat(gesture-controller): disable/enable scrolling

This commit is contained in:
Manu Mtz.-Almeida
2016-07-14 00:52:43 +02:00
parent d230cb40fe
commit 72c24bc927
5 changed files with 46 additions and 39 deletions

View File

@ -1,6 +1,6 @@
import { Directive, ElementRef, Input } from '@angular/core';
import { AppRoot } from '../app/app';
import { DisableScroll, GestureController, GestureDelegate } from '../../gestures/gesture-controller';
import { isTrueProperty } from '../../util/util';
@ -16,41 +16,21 @@ import { isTrueProperty } from '../../util/util';
},
})
export class Backdrop {
private static nuBackDrops: number = 0;
private static push(appRoot: AppRoot) {
if (this.nuBackDrops === 0) {
appRoot.disableScroll = true;
}
this.nuBackDrops++;
}
private static pop(appRoot: AppRoot) {
if (this.nuBackDrops > 0) {
this.nuBackDrops--;
if (this.nuBackDrops === 0) {
appRoot.disableScroll = false;
}
}
}
private pushed: boolean = false;
private _gestureID: number = null;
@Input() disableScroll = true;
constructor(private _appRoot: AppRoot, private _elementRef: ElementRef) {}
constructor(private _gestureCtrl: GestureController, private _elementRef: ElementRef) {}
ngOnInit() {
if (isTrueProperty(this.disableScroll)) {
Backdrop.push(this._appRoot);
this.pushed = true;
this._gestureID = this._gestureCtrl.newID();
this._gestureCtrl.disableScroll(this._gestureID);
}
}
ngOnDestroy() {
if (this.pushed) {
Backdrop.pop(this._appRoot);
this.pushed = false;
if (this._gestureID) {
this._gestureCtrl.enableScroll(this._gestureID);
}
}