feat: enhance video player progress bar touch interaction by adding native touch event handling and increasing touch target area.

This commit is contained in:
kuekhaoyang
2026-02-04 17:02:23 +08:00
parent 157ab4345f
commit 9e6275f68b
2 changed files with 38 additions and 1 deletions
+15
View File
@@ -47,6 +47,21 @@
overflow: visible;
user-select: none;
-webkit-user-select: none;
touch-action: none;
/* Prevent page scrolling during drag */
-webkit-touch-callout: none;
/* Prevent iOS callout */
}
/* Increase touch target area for mobile */
.slider-track::before {
content: '';
position: absolute;
top: -16px;
left: 0;
right: 0;
bottom: -16px;
z-index: 1;
}
.slider-track.h-1 {
@@ -108,7 +108,29 @@ export function useProgressControls({
document.removeEventListener('touchend', handleTouchEnd);
document.removeEventListener('touchcancel', handleTouchEnd);
};
}, [duration, isDraggingProgressRef, progressBarRef, videoRef, setCurrentTime]);
}, [duration, isDraggingProgressRef, progressBarRef, videoRef, setCurrentTime, getEventPos]);
// Attach touchstart with passive: false to allow preventDefault (React uses passive by default)
useEffect(() => {
const progressBar = progressBarRef.current;
if (!progressBar) return;
const handleNativeTouchStart = (e: TouchEvent) => {
e.preventDefault();
isDraggingProgressRef.current = true;
if (!videoRef.current) return;
const rect = progressBar.getBoundingClientRect();
const pos = getEventPos(e, rect);
const newTime = pos * duration;
lastDragTimeRef.current = newTime;
setCurrentTime(newTime);
};
progressBar.addEventListener('touchstart', handleNativeTouchStart, { passive: false });
return () => {
progressBar.removeEventListener('touchstart', handleNativeTouchStart);
};
}, [progressBarRef, videoRef, isDraggingProgressRef, duration, setCurrentTime, getEventPos]);
const progressActions = useMemo(() => ({
handleProgressClick,