From 697fcc80e25577337f78e4735b7019c35bdf0ac8 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 5 Apr 2020 13:54:38 +0200 Subject: [PATCH] Always call preventDefault on canvas touch events to fix alt double taps on iOS 13.4. --- src/web/stella/driver/TouchIO.ts | 34 +++----------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/web/stella/driver/TouchIO.ts b/src/web/stella/driver/TouchIO.ts index 2c676219..8f7c4fd2 100644 --- a/src/web/stella/driver/TouchIO.ts +++ b/src/web/stella/driver/TouchIO.ts @@ -85,13 +85,7 @@ class TouchIO { this._canvas.removeEventListener('touchmove', this._onTouchMove); } - private _cancelEvent(touch: NormalizedTouch): boolean { - return touch.type !== TouchType.alt; - } - private _onTouchStart = (e: TouchEvent): void => { - let cancel = false; - for (let i = 0; i < e.changedTouches.length; i++) { const normalizedTouch = new NormalizedTouch(e.changedTouches.item(i), this._canvas), id = normalizedTouch.touch.identifier; @@ -152,20 +146,12 @@ class TouchIO { default: throw new Error('invalid touch type'); } - - if (this._cancelEvent(normalizedTouch) || this._fullscreenDoubleTapDetector.isDispatching()) { - cancel = true; - } } - if (cancel) { - e.preventDefault(); - } + e.preventDefault(); }; private _onTouchEnd = (e: TouchEvent): void => { - let cancel = false; - for (let i = 0; i < e.changedTouches.length; i++) { const normalizedTouch = this._pendingTouches.get(e.changedTouches.item(i).identifier); @@ -173,10 +159,6 @@ class TouchIO { continue; } - if (this._cancelEvent(normalizedTouch) || this._fullscreenDoubleTapDetector.isDispatching()) { - cancel = true; - } - switch (normalizedTouch.type) { case TouchType.alt: this._isAlt = false; @@ -213,14 +195,10 @@ class TouchIO { this._pendingTouches.delete(normalizedTouch.touch.identifier); } - if (cancel) { - e.preventDefault(); - } + e.preventDefault(); }; private _onTouchMove = (e: TouchEvent): void => { - let cancel = false; - for (let i = 0; i < e.changedTouches.length; i++) { const touch = e.changedTouches.item(i), normalizedTouch = this._pendingTouches.get(touch.identifier); @@ -229,10 +207,6 @@ class TouchIO { continue; } - if (this._cancelEvent(normalizedTouch)) { - cancel = true; - } - if (normalizedTouch.type !== TouchType.joystick) { continue; } @@ -255,9 +229,7 @@ class TouchIO { } } - if (cancel) { - e.preventDefault(); - } + e.preventDefault(); }; toggleFullscreen: Event;