Allow page scrolling over the game canvas (#510)
Swiping over the game canvas prevented the surrounding page from scrolling, making the platform chat difficult to reach on a phone. Allow native vertical scrolling and pinch zoom while retaining browser-generated mouse events for taps. Plain wheel gestures scroll the page; Ctrl/Command-wheel and fullscreen retain board zoom. The change intercepts only the canvas library's blanket touch/wheel cancellation. Validation against the built published-compatible WASM viewer: native touch and wheel scrolling, no move emitted during a swipe, and one mouse press/release pair per tap.
This commit is contained in:
parent
3d1b5753d6
commit
0f1f9b7ccf
2 changed files with 18 additions and 0 deletions
16
client/js/src/page-scrolling.js
Normal file
16
client/js/src/page-scrolling.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export function bindPageScrolling(canvas) {
|
||||
// Miniquad cancels every touch, including swipes meant for the surrounding BGS page.
|
||||
// Let the browser scroll and generate compatibility mouse events for taps instead.
|
||||
const nativeTouch = (event) => event.stopImmediatePropagation();
|
||||
for (const type of ["touchstart", "touchmove", "touchend", "touchcancel"])
|
||||
canvas.addEventListener(type, nativeTouch, { capture: true, passive: true });
|
||||
canvas.style.touchAction = "pan-y pinch-zoom";
|
||||
canvas.addEventListener(
|
||||
"wheel",
|
||||
(event) => {
|
||||
if (!event.ctrlKey && !event.metaKey && !document.fullscreenElement)
|
||||
event.stopImmediatePropagation();
|
||||
},
|
||||
{ capture: true, passive: true },
|
||||
);
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { bindPageScrolling } from "./page-scrolling";
|
||||
import init, { set_wasm } from "../../dist/remote_client";
|
||||
|
||||
function dynamicallyLoadScript(url, onload) {
|
||||
|
|
@ -9,6 +10,7 @@ function dynamicallyLoadScript(url, onload) {
|
|||
}
|
||||
|
||||
export async function run({ selector, control }) {
|
||||
bindPageScrolling(document.querySelector(selector));
|
||||
let wbg = await init();
|
||||
miniquad_add_plugin({
|
||||
register_plugin: (a) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue