From 2724ba8283412afd9b404471787433d7b9675d16 Mon Sep 17 00:00:00 2001 From: ntr Date: Sun, 7 Apr 2019 14:02:20 +1000 Subject: [PATCH] touch events --- client/package.json | 2 +- client/src/components/vbox.component.jsx | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/client/package.json b/client/package.json index 2911f2fa..e5212454 100644 --- a/client/package.json +++ b/client/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "start": "parcel index.html --port 40080 --no-source-maps", + "start": "parcel index.html --host 0.0.0.0 --port 40080 --no-source-maps", "build": "rm -rf dist && parcel build index.html", "lint": "eslint --fix --ext .jsx src/", "test": "echo \"Error: no test specified\" && exit 1" diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index 6589ded9..bd4625a0 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -50,10 +50,13 @@ function Vbox(args) { function vboxTouchEnd(e, i, j) { if (vboxTimer) { clearTimeout(vboxTimer); - if (free[i][j]) setInfo('item', free[i][j]); } + return true; + } + + function vboxTouchMove(e) { + if (vboxTimer) clearTimeout(vboxTimer); e.stopPropagation(); - e.preventDefault(); return true; } @@ -63,6 +66,7 @@ function Vbox(args) { key={j} onTouchStart={e => vboxTouchStart(e, i, j)} onTouchEnd={e => vboxTouchEnd(e, i, j)} + onTouchMove={e => vboxTouchMove(e)} onClick={() => { if (c) return setInfo('item', c); }} onDblClick={() => sendVboxAccept(j, i) } @@ -103,14 +107,25 @@ function Vbox(args) { if (reclaiming && i) sendVboxReclaim(i); else if (vbox.bound[i]) setActiveVar(i); } + return true; + } + + function boundTouchMove(e) { + if (boundTimer) clearTimeout(boundTimer); e.stopPropagation(); - e.preventDefault(); return true; } function boundClick(e, i) { if (reclaiming && i) sendVboxReclaim(i); - else if (vbox.bound[i]) setActiveVar(i); + else if (vbox.bound[i]) { + const insert = combiner.findIndex(j => j === null); + if (insert === -1) return setCombiner([i, null, null]); + combiner[insert] = i; + boundTimer = null; + return setCombiner(combiner); + } + return false; } const boundTds = range(0, 9).map(i => {