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:
@ -304,6 +304,7 @@ class E2EPage {
|
|||||||
</ion-header>
|
</ion-header>
|
||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
Hi, I'm Bob, and I'm a modal.
|
Hi, I'm Bob, and I'm a modal.
|
||||||
|
<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
|
@ -31,6 +31,11 @@ export class App {
|
|||||||
*/
|
*/
|
||||||
clickBlock: ClickBlock;
|
clickBlock: ClickBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
appRoot: AppRoot;
|
||||||
|
|
||||||
viewDidLoad: EventEmitter<any> = new EventEmitter();
|
viewDidLoad: EventEmitter<any> = new EventEmitter();
|
||||||
viewWillEnter: EventEmitter<any> = new EventEmitter();
|
viewWillEnter: EventEmitter<any> = new EventEmitter();
|
||||||
viewDidEnter: EventEmitter<any> = new EventEmitter();
|
viewDidEnter: EventEmitter<any> = new EventEmitter();
|
||||||
@ -86,6 +91,17 @@ export class App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
setScrollDisabled(disabled: boolean) {
|
||||||
|
if (!this.appRoot) {
|
||||||
|
console.error('appRoot is missing, scrolling can not be enabled/disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.appRoot.disableScroll = disabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* Boolean if the app is actively enabled or not.
|
* Boolean if the app is actively enabled or not.
|
||||||
@ -282,9 +298,13 @@ export class AppRoot {
|
|||||||
@ViewChild('anchor', {read: ViewContainerRef}) private _viewport: ViewContainerRef;
|
@ViewChild('anchor', {read: ViewContainerRef}) private _viewport: ViewContainerRef;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _cmp: UserComponent,
|
private _cmp: UserComponent,
|
||||||
private _cr: ComponentResolver,
|
private _cr: ComponentResolver,
|
||||||
private _renderer: Renderer) {}
|
private _renderer: Renderer,
|
||||||
|
app: App
|
||||||
|
) {
|
||||||
|
app.appRoot = this;
|
||||||
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
// load the user app's root component
|
// load the user app's root component
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Directive, ElementRef, Input } from '@angular/core';
|
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';
|
import { isTrueProperty } from '../../util/util';
|
||||||
|
|
||||||
|
|
||||||
@ -16,41 +16,21 @@ import { isTrueProperty } from '../../util/util';
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
export class Backdrop {
|
export class Backdrop {
|
||||||
private static nuBackDrops: number = 0;
|
private _gestureID: number = null;
|
||||||
|
|
||||||
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;
|
|
||||||
@Input() disableScroll = true;
|
@Input() disableScroll = true;
|
||||||
|
|
||||||
constructor(private _appRoot: AppRoot, private _elementRef: ElementRef) {}
|
constructor(private _gestureCtrl: GestureController, private _elementRef: ElementRef) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (isTrueProperty(this.disableScroll)) {
|
if (isTrueProperty(this.disableScroll)) {
|
||||||
Backdrop.push(this._appRoot);
|
this._gestureID = this._gestureCtrl.newID();
|
||||||
this.pushed = true;
|
this._gestureCtrl.disableScroll(this._gestureID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
if (this.pushed) {
|
if (this._gestureID) {
|
||||||
Backdrop.pop(this._appRoot);
|
this._gestureCtrl.enableScroll(this._gestureID);
|
||||||
this.pushed = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ export function ionicProviders(customProviders?: Array<any>, config?: any): any[
|
|||||||
provide(Events, {useValue: events}),
|
provide(Events, {useValue: events}),
|
||||||
provide(FeatureDetect, {useValue: featureDetect}),
|
provide(FeatureDetect, {useValue: featureDetect}),
|
||||||
Form,
|
Form,
|
||||||
|
GestureController,
|
||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
Keyboard,
|
Keyboard,
|
||||||
LoadingController,
|
LoadingController,
|
||||||
@ -78,7 +79,6 @@ export function ionicProviders(customProviders?: Array<any>, config?: any): any[
|
|||||||
TapClick,
|
TapClick,
|
||||||
ToastController,
|
ToastController,
|
||||||
Translate,
|
Translate,
|
||||||
GestureController,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isPresent(customProviders)) {
|
if (isPresent(customProviders)) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { forwardRef, Inject, Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { App } from '../components/app/app';
|
import { App } from '../components/app/app';
|
||||||
|
|
||||||
export const enum GesturePriority {
|
export const enum GesturePriority {
|
||||||
@ -30,12 +29,17 @@ export class GestureController {
|
|||||||
private requestedStart: { [eventId: number]: number } = {};
|
private requestedStart: { [eventId: number]: number } = {};
|
||||||
private disabledGestures: { [eventName: string]: Set<number> } = {};
|
private disabledGestures: { [eventName: string]: Set<number> } = {};
|
||||||
private disabledScroll: Set<number> = new Set<number>();
|
private disabledScroll: Set<number> = new Set<number>();
|
||||||
private appRoot: App;
|
|
||||||
private capturedID: number = null;
|
private capturedID: number = null;
|
||||||
|
|
||||||
|
constructor(@Inject(forwardRef(() => App)) private _app: App) { }
|
||||||
|
|
||||||
create(name: string, opts: GestureOptions = {}): GestureDelegate {
|
create(name: string, opts: GestureOptions = {}): GestureDelegate {
|
||||||
|
return new GestureDelegate(name, this.newID(), this, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
newID(): number {
|
||||||
let id = this.id; this.id++;
|
let id = this.id; this.id++;
|
||||||
return new GestureDelegate(name, id, this, opts);
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
start(gestureName: string, id: number, priority: number): boolean {
|
start(gestureName: string, id: number, priority: number): boolean {
|
||||||
@ -94,16 +98,18 @@ export class GestureController {
|
|||||||
disableScroll(id: number) {
|
disableScroll(id: number) {
|
||||||
let isEnabled = !this.isScrollDisabled();
|
let isEnabled = !this.isScrollDisabled();
|
||||||
this.disabledScroll.add(id);
|
this.disabledScroll.add(id);
|
||||||
if (isEnabled && this.isScrollDisabled()) {
|
if (this._app && isEnabled && this.isScrollDisabled()) {
|
||||||
// this.appRoot.disableScroll = true;
|
console.debug('GestureController: Disabling scrolling');
|
||||||
|
this._app.setScrollDisabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableScroll(id: number) {
|
enableScroll(id: number) {
|
||||||
let isDisabled = this.isScrollDisabled();
|
let isDisabled = this.isScrollDisabled();
|
||||||
this.disabledScroll.delete(id);
|
this.disabledScroll.delete(id);
|
||||||
if (isDisabled && !this.isScrollDisabled()) {
|
if (this._app && isDisabled && !this.isScrollDisabled()) {
|
||||||
// this.appRoot.disableScroll = false;
|
console.debug('GestureController: Enabling scrolling');
|
||||||
|
this._app.setScrollDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user