mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00
feat(gesture-controller): disable/enable scrolling
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user