Skip to content

Commit

Permalink
fix long press with distance threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomax committed Aug 8, 2024
1 parent 2166426 commit 5f618a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions demo/issue-77b/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<script type="module">
import { enableDragDropTouch } from "https://drag-drop-touch-js.github.io/dragdroptouch/dist/drag-drop-touch.esm.min.js";
import { enableDragDropTouch } from "/dist/drag-drop-touch.debug.esm.js";

function enableBaseLine() {
enableDragDropTouch();
Expand All @@ -17,7 +17,7 @@
function enablePressHold5() {
enableDragDropTouch(document, document, {
isPressHoldMode: true,
pressHoldThresholdPixels: 5,
pressHoldThresholdPixels: 50,
});
}

Expand Down
2 changes: 1 addition & 1 deletion dist/drag-drop-touch.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ var DragDropTouch = class {
* @returns
*/
_getDelta(e) {
if (!this._ptDown || this.configuration.isPressHoldMode) return 0;
if (!this._ptDown) return 0;
const { x, y } = this._ptDown;
const p = pointFrom(e);
return ((p.x - x) ** 2 + (p.y - y) ** 2) ** 0.5;
Expand Down
2 changes: 1 addition & 1 deletion dist/drag-drop-touch.esm.min.js

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

10 changes: 7 additions & 3 deletions ts/drag-drop-touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ class DragDropTouch {
_shouldStartDragging(e: TouchEvent) {
let delta = this._getDelta(e);
if (this.configuration.isPressHoldMode) {
DEBUG: console.log(
this.configuration.isPressHoldMode,
delta,
this.configuration.pressHoldThresholdPixels,
);
return delta >= this.configuration.pressHoldThresholdPixels;
}
return delta > this.configuration.dragThresholdPixels;
Expand All @@ -440,9 +445,8 @@ class DragDropTouch {
* @returns
*/
_getDelta(e: TouchEvent) {
// if there is no active touch, or we're already in
// long press mode, we don't need to calculate anything.
if (!this._ptDown || this.configuration.isPressHoldMode) return 0;
// if there is no active touch we don't need to calculate anything.
if (!this._ptDown) return 0;

// Determine how `far` from the event coordinate our
// original touch coordinate was.
Expand Down

0 comments on commit 5f618a7

Please sign in to comment.