From 8bc0aa3e7b36380227492d5b779dfc2d3a84319e Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 2 Jan 2023 09:20:49 +0900 Subject: :art: --- packages/frontend/src/scripts/touch.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'packages/frontend/src/scripts') diff --git a/packages/frontend/src/scripts/touch.ts b/packages/frontend/src/scripts/touch.ts index 5251bc2e27..4afd0e5dd4 100644 --- a/packages/frontend/src/scripts/touch.ts +++ b/packages/frontend/src/scripts/touch.ts @@ -1,23 +1,13 @@ -const isTouchSupported = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0; +import { deviceKind } from '@/scripts/device-kind'; -export let isTouchUsing = false; +const isTouchSupported = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0; -export let isScreenTouching = false; +export let isTouchUsing = deviceKind === 'tablet' || deviceKind === 'smartphone'; -if (isTouchSupported) { +if (isTouchSupported && !isTouchUsing) { window.addEventListener('touchstart', () => { // maxTouchPointsなどでの判定だけだと、「タッチ機能付きディスプレイを使っているがマウスでしか操作しない」場合にも // タッチで使っていると判定されてしまうため、実際に一度でもタッチされたらtrueにする isTouchUsing = true; - - isScreenTouching = true; - }, { passive: true }); - - window.addEventListener('touchend', () => { - // 子要素のtouchstartイベントでstopPropagation()が呼ばれると親要素に伝搬されずタッチされたと判定されないため、 - // touchendイベントでもtouchstartイベントと同様にtrueにする - isTouchUsing = true; - - isScreenTouching = false; }, { passive: true }); } -- cgit v1.2.3-freya