#56 : Update pausable handlers

This commit is contained in:
Vadim
2021-08-12 22:07:01 +03:00
parent ebdbdaa453
commit 52c11c2480
2 changed files with 41 additions and 6 deletions

View File

@@ -18,8 +18,26 @@ export function createDispatcher(source) {
export function getIsTouchable() {
return (
('ontouchstart' in window) ||
// ('ontouchstart' in window) || // not changing value during browser view switching (mobile <-> desktop)
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0)
)
}
export function addTouchableChangeEventListener(cb) {
let isTouchable = getIsTouchable();
cb(isTouchable)
function handleResize() {
const isTouchableNext = getIsTouchable();
if (isTouchable !== isTouchableNext) {
cb(isTouchableNext)
isTouchable = isTouchableNext
}
}
addResizeEventListener(handleResize)
return () => {
removeResizeEventListener(handleResize)
}
}