From 94335a9994ced9f88176259177ddee883c3b07c5 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Sat, 11 Jan 2025 18:00:29 -0500 Subject: [PATCH] Fix mobile touch events (#233) Ported from #229 --------- Co-authored-by: Johnathon Selstad --- demos/web-editor/web/src/index.html | 2 ++ demos/web-editor/web/src/index.ts | 45 +++++++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/demos/web-editor/web/src/index.html b/demos/web-editor/web/src/index.html index ee6db76c..e09f9726 100644 --- a/demos/web-editor/web/src/index.html +++ b/demos/web-editor/web/src/index.html @@ -26,6 +26,8 @@ max-height: 512px; outline: 1px solid #bbb; margin-bottom: 12px; + user-select: none; + touch-action: none; } span#status { display: block; diff --git a/demos/web-editor/web/src/index.ts b/demos/web-editor/web/src/index.ts index 9f593bfc..abc39b5b 100644 --- a/demos/web-editor/web/src/index.ts +++ b/demos/web-editor/web/src/index.ts @@ -76,21 +76,36 @@ class App { scene.canvas.addEventListener("contextmenu", (event) => { event.preventDefault(); }); - scene.canvas.addEventListener("mousedown", (event) => { - if (event.button === 0) { - scene.beginTranslate(event); - } else if (event.button === 2) { - scene.beginRotate(event); - } - }); - window.addEventListener("mouseup", (event) => { - scene.endDrag(); - }); - window.addEventListener("mousemove", (event) => { - if (scene.drag(event)) { - requestRedraw(); - } - }); + scene.canvas.addEventListener( + "pointerdown", + (event) => { + event.preventDefault(); + if (event.button === 0) { + scene.beginTranslate(event); + } else if (event.button === 2) { + scene.beginRotate(event); + } + }, + { passive: false }, + ); + window.addEventListener( + "pointerup", + (event) => { + event.preventDefault(); + scene.endDrag(); + }, + { passive: false }, + ); + window.addEventListener( + "pointermove", + (event) => { + event.preventDefault(); + if (scene.drag(event)) { + requestRedraw(); + } + }, + { passive: false }, + ); this.scene = scene; // Hot-patch the gyroid script to be eval (instead of exec) flavored