From 7917ba96ef49ceaaaa4aa421bbf966b42db2c7dd Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Sun, 26 Aug 2018 01:26:36 +0200 Subject: [PATCH] refactor(all): consistent gesture events --- .../components/item-sliding/item-sliding.tsx | 12 +++++----- core/src/components/menu/menu.tsx | 12 +++++----- core/src/components/nav/nav.tsx | 24 ++++++++++--------- .../picker-column/picker-column.tsx | 12 +++++----- core/src/components/range/range.tsx | 12 +++++----- .../reorder-group/reorder-group.tsx | 14 +++++------ core/src/components/toggle/toggle.tsx | 12 +++++----- 7 files changed, 50 insertions(+), 48 deletions(-) diff --git a/core/src/components/item-sliding/item-sliding.tsx b/core/src/components/item-sliding/item-sliding.tsx index 4b71f3dd46..0d8f5b7a08 100644 --- a/core/src/components/item-sliding/item-sliding.tsx +++ b/core/src/components/item-sliding/item-sliding.tsx @@ -76,9 +76,9 @@ export class ItemSliding { gesturePriority: 20, threshold: 5, canStart: this.canStart.bind(this), - onStart: this.onDragStart.bind(this), - onMove: this.onDragMove.bind(this), - onEnd: this.onDragEnd.bind(this), + onStart: this.onStart.bind(this), + onMove: this.onMove.bind(this), + onEnd: this.onEnd.bind(this), }); this.disabledChanged(); } @@ -166,7 +166,7 @@ export class ItemSliding { return !!(this.rightOptions || this.leftOptions); } - private onDragStart() { + private onStart() { if (this.list) { this.list.setOpenItem(this.el); } @@ -185,7 +185,7 @@ export class ItemSliding { } } - private onDragMove(gesture: GestureDetail) { + private onMove(gesture: GestureDetail) { if (this.optsDirty) { this.calculateOptsWidth(); } @@ -212,7 +212,7 @@ export class ItemSliding { this.setOpenAmount(openAmount, false); } - private onDragEnd(gesture: GestureDetail) { + private onEnd(gesture: GestureDetail) { const velocity = gesture.velocityX; let restingPoint = (this.openAmount > 0) diff --git a/core/src/components/menu/menu.tsx b/core/src/components/menu/menu.tsx index 3b1a4aa5d5..fba529b791 100644 --- a/core/src/components/menu/menu.tsx +++ b/core/src/components/menu/menu.tsx @@ -183,9 +183,9 @@ export class Menu implements MenuI { threshold: 10, canStart: this.canStart.bind(this), onWillStart: this.onWillStart.bind(this), - onStart: this.onDragStart.bind(this), - onMove: this.onDragMove.bind(this), - onEnd: this.onDragEnd.bind(this), + onStart: this.onStart.bind(this), + onMove: this.onMove.bind(this), + onEnd: this.onEnd.bind(this), }); // mask it as enabled / disabled @@ -329,7 +329,7 @@ export class Menu implements MenuI { return this.loadAnimation(); } - private onDragStart() { + private onStart() { if (!this.isAnimating || !this.animation) { assert(false, 'isAnimating has to be true'); return; @@ -339,7 +339,7 @@ export class Menu implements MenuI { this.animation.reverse(this._isOpen).progressStart(); } - private onDragMove(detail: GestureDetail) { + private onMove(detail: GestureDetail) { if (!this.isAnimating || !this.animation) { assert(false, 'isAnimating has to be true'); return; @@ -350,7 +350,7 @@ export class Menu implements MenuI { this.animation.progressStep(stepValue); } - private onDragEnd(detail: GestureDetail) { + private onEnd(detail: GestureDetail) { if (!this.isAnimating || !this.animation) { assert(false, 'isAnimating has to be true'); return; diff --git a/core/src/components/nav/nav.tsx b/core/src/components/nav/nav.tsx index deae4691cc..b30a4fc407 100644 --- a/core/src/components/nav/nav.tsx +++ b/core/src/components/nav/nav.tsx @@ -116,10 +116,10 @@ export class Nav implements NavOutlet { gestureName: 'goback-swipe', gesturePriority: 30, threshold: 10, - canStart: this.canSwipeBack.bind(this), - onStart: this.swipeBackStart.bind(this), - onMove: this.swipeBackProgress.bind(this), - onEnd: this.swipeBackEnd.bind(this), + canStart: this.canStart.bind(this), + onStart: this.onStart.bind(this), + onMove: this.onMove.bind(this), + onEnd: this.onEnd.bind(this), }); this.swipeGestureChanged(); } @@ -888,7 +888,13 @@ export class Nav implements NavOutlet { } } - private swipeBackStart() { + private canStart(): boolean { + return !!this.swipeGesture && + !this.isTransitioning && + this.canGoBack(); + } + + private onStart() { if (this.isTransitioning || this.transInstr.length > 0) { return; } @@ -909,7 +915,7 @@ export class Nav implements NavOutlet { ); } - private swipeBackProgress(detail: GestureDetail) { + private onMove(detail: GestureDetail) { if (this.sbTrns) { // continue to disable the app while actively dragging this.isTransitioning = true; @@ -922,7 +928,7 @@ export class Nav implements NavOutlet { } } - private swipeBackEnd(detail: GestureDetail) { + private onEnd(detail: GestureDetail) { if (this.sbTrns) { // the swipe back gesture has ended const delta = detail.deltaX; @@ -945,10 +951,6 @@ export class Nav implements NavOutlet { } } - private canSwipeBack(): boolean { - return !!this.swipeGesture && !this.isTransitioning && this.canGoBack(); - } - render() { return [ this.mode === 'ios' &&