forked from misskey-dev/misskey
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
} |