#56 : Fix touchable handlers

This commit is contained in:
Vadim
2021-08-16 09:46:35 +03:00
parent efdca46391
commit 4e6f37ca91
6 changed files with 17 additions and 94 deletions

View File

@@ -1,5 +1,3 @@
import { setIntervalImmediate } from './interval'
// resize event
export function addResizeEventListener(cb) {
window.addEventListener('resize', cb)
@@ -17,29 +15,3 @@ export function createDispatcher(source) {
)
}
}
export function getIsTouchable() {
return (
('ontouchstart' in window)
// || // not changing value during browser view switching (mobile <-> desktop)
// (navigator.maxTouchPoints > 0) ||
// (navigator.msMaxTouchPoints > 0)
)
}
export function addTouchableChangeEventListener(cb) {
let isTouchable = null
function handleTouchableChange() {
const isTouchableNext = getIsTouchable();
if (isTouchable !== isTouchableNext) {
cb(isTouchableNext)
isTouchable = isTouchableNext
}
}
const interval = setIntervalImmediate(handleTouchableChange, 500);
return () => {
clearInterval(interval)
}
}