fix(all): gesture controller can block scrolling

fixes #15725
This commit is contained in:
Manu Mtz.-Almeida
2018-09-25 17:45:02 +02:00
parent 29d00da2b4
commit 633360fcba
7 changed files with 35 additions and 26 deletions

View File

@@ -29,8 +29,8 @@ export class GestureController {
*/
createBlocker(opts: BlockerConfig = {}): BlockerDelegate {
return new BlockerDelegate(
this.newID(),
this,
this.newID(),
opts.disable,
!!opts.disableScroll
);
@@ -95,10 +95,16 @@ export class GestureController {
disableScroll(id: number) {
this.disabledScroll.add(id);
if (this.disabledScroll.size === 1) {
this.doc.body.classList.add(BACKDROP_NO_SCROLL);
}
}
enableScroll(id: number) {
this.disabledScroll.delete(id);
if (this.disabledScroll.size === 0) {
this.doc.body.classList.remove(BACKDROP_NO_SCROLL);
}
}
canStart(gestureName: string): boolean {
@@ -140,7 +146,7 @@ export class GestureDelegate {
private ctrl?: GestureController;
constructor(
ctrl: any,
ctrl: GestureController,
private id: number,
private name: string,
private priority: number,
@@ -199,8 +205,8 @@ export class BlockerDelegate {
private ctrl?: GestureController;
constructor(
ctrl: GestureController,
private id: number,
ctrl: any,
private disable: string[] | undefined,
private disableScroll: boolean
) {
@@ -253,4 +259,5 @@ export interface BlockerConfig {
disableScroll?: boolean;
}
export const gestureController = new GestureController(document);
const BACKDROP_NO_SCROLL = 'backdrop-no-scroll';
export const GESTURE_CONTROLLER = new GestureController(document);

View File

@@ -1,6 +1,6 @@
import { QueueApi } from '@stencil/core';
import { gestureController } from './gesture-controller';
import { GESTURE_CONTROLLER } from './gesture-controller';
import { createPointerEvents } from './pointer-events';
import { createPanRecognizer } from './recognizers';
@@ -52,7 +52,7 @@ export function createGesture(config: GestureConfig): Gesture {
);
const pan = createPanRecognizer(finalConfig.direction, finalConfig.threshold, finalConfig.maxAngle);
const gesture = gestureController.createGesture({
const gesture = GESTURE_CONTROLLER.createGesture({
name: config.gestureName,
priority: config.gesturePriority,
disableScroll: config.disableScroll