unified-video-framework
Version:
Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more
45 lines • 1.55 kB
JavaScript
import { useRef, useCallback } from 'react';
export function usePortraitGestures(containerRef, handlers) {
const tapTimerRef = useRef(null);
const lastTapTimeRef = useRef(0);
const DOUBLE_TAP_DELAY = 280;
const handleTap = useCallback((e) => {
const target = e.target;
if (target.closest('button, a, input, [data-interactive]'))
return;
const now = Date.now();
const rect = containerRef.current?.getBoundingClientRect();
if (!rect)
return;
let clientX;
let clientY;
if ('touches' in e) {
const touch = e.changedTouches[0];
clientX = touch.clientX;
clientY = touch.clientY;
}
else {
clientX = e.clientX;
clientY = e.clientY;
}
const relX = clientX - rect.left;
const relY = clientY - rect.top;
if (now - lastTapTimeRef.current < DOUBLE_TAP_DELAY) {
if (tapTimerRef.current) {
clearTimeout(tapTimerRef.current);
tapTimerRef.current = null;
}
lastTapTimeRef.current = 0;
handlers.onDoubleTap(relX, relY);
}
else {
lastTapTimeRef.current = now;
tapTimerRef.current = setTimeout(() => {
tapTimerRef.current = null;
handlers.onSingleTap();
}, DOUBLE_TAP_DELAY);
}
}, [containerRef, handlers]);
return { handleTap };
}
//# sourceMappingURL=usePortraitGestures.js.map