Skip to content

Commit

Permalink
fix(events): android fast drag was interpreted as tap event (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-rr committed Oct 29, 2021
1 parent d6aa8d1 commit ac7093e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
16 changes: 10 additions & 6 deletions dist/cupertino-pane.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Released under the MIT License
*
* Released on: October 26, 2021
* Released on: October 29, 2021
*/

/*! *****************************************************************************
Expand Down Expand Up @@ -349,7 +349,6 @@ class Events {
}
}
touchStart(t) {
// Liam the best :)
// Event emitter
this.settings.onDragStart(t);
// Allow clicks by default -> disallow on move (allow click with disabled drag)
Expand Down Expand Up @@ -385,6 +384,8 @@ class Events {
// Event emitter
t.delta = ((_a = this.steps[0]) === null || _a === void 0 ? void 0 : _a.posY) - clientY;
this.settings.onDrag(t);
// Disallow accidentaly clicks while slide gestures
this.allowClick = false;
if (this.instance.disableDragEvents) {
this.steps = [];
return;
Expand All @@ -404,6 +405,10 @@ class Events {
// Patch for 'touchmove' first start slowly events with velocity
let newVal = this.instance.getPanelTransformY()
+ ((this.steps.length < 2) ? (diffY * velocityY) : diffY);
// No Y changes
if (!Math.abs(diffY)) {
return;
}
// textarea scrollbar
if (this.isFormElement(t.target)
&& this.isElementScrollable(t.target)) {
Expand Down Expand Up @@ -503,8 +508,6 @@ class Events {
return;
}
}
// Disallow accidentaly clicks while slide gestures
this.allowClick = false;
this.instance.checkOpacityAttr(newVal);
this.instance.checkOverflowAttr(newVal);
this.instance.doTransition({ type: 'move', translateY: newVal });
Expand Down Expand Up @@ -544,8 +547,9 @@ class Events {
this.breakpoints.currentBreakpoint = closest;
// Event emitter
this.settings.onDragEnd(t);
// tap event
if (isNaN(diff) || blurTapEvent) {
// touchend with allowClick === tapped event (no move triggered)
// skip next functions
if (this.allowClick || blurTapEvent) {
return;
}
this.instance.checkOpacityAttr(this.breakpoints.currentBreakpoint);
Expand Down
4 changes: 2 additions & 2 deletions dist/cupertino-pane.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cupertino-pane.esm.min.js.map

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions dist/cupertino-pane.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cupertino-pane.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/cupertino-pane.min.js

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class Events {
*/
public touchStartCb = (t) => this.touchStart(t);
private touchStart(t) {
// Liam the best :)

// Event emitter
this.settings.onDragStart(t as CustomEvent);

Expand Down Expand Up @@ -210,6 +210,9 @@ export class Events {
// Event emitter
t.delta = this.steps[0]?.posY - clientY;
this.settings.onDrag(t);

// Disallow accidentaly clicks while slide gestures
this.allowClick = false;

if (this.instance.disableDragEvents) {
this.steps = [];
Expand All @@ -231,6 +234,11 @@ export class Events {
let newVal = this.instance.getPanelTransformY()
+ ((this.steps.length < 2) ? (diffY * velocityY) : diffY);

// No Y changes
if (!Math.abs(diffY)) {
return;
}

// textarea scrollbar
if (this.isFormElement(t.target)
&& this.isElementScrollable(t.target)) {
Expand Down Expand Up @@ -341,9 +349,6 @@ export class Events {
}
}

// Disallow accidentaly clicks while slide gestures
this.allowClick = false;

this.instance.checkOpacityAttr(newVal);
this.instance.checkOverflowAttr(newVal);
this.instance.doTransition({type: 'move', translateY: newVal});
Expand All @@ -363,7 +368,7 @@ export class Events {
// Determinate nearest point
let closest = this.breakpoints.getClosestBreakY();
// Swipe - next (if differ > 10)
const diff = this.steps[this.steps.length - 1]?.posY - this.steps[this.steps.length - 2]?.posY;
const diff = this.steps[this.steps.length - 1]?.posY - this.steps[this.steps.length - 2]?.posY;
// Set sensivity lower for web
const swipeNextSensivity = window.hasOwnProperty('cordova')
? (this.settings.fastSwipeSensivity + 2) : this.settings.fastSwipeSensivity;
Expand Down Expand Up @@ -394,8 +399,9 @@ export class Events {
// Event emitter
this.settings.onDragEnd(t as CustomEvent);

// tap event
if (isNaN(diff) || blurTapEvent) {
// touchend with allowClick === tapped event (no move triggered)
// skip next functions
if (this.allowClick || blurTapEvent) {
return;
}

Expand Down

0 comments on commit ac7093e

Please sign in to comment.