Skip to content

Commit 0957e5d

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
fix(timeline): Fix trackpad pinch-zoom behavior
- Replaced React's onWheel with a non-passive native wheel listener - Prevents page zoom when using touchpad pinch/scroll on the timeline component
1 parent 7b22db9 commit 0957e5d

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

src/components/VideoTimeline.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,26 @@ export const VideoTimeline = ({
148148
}
149149
}, [isScrubbing, onSeek, duration, zoomLevel, scrollLeft]); // Re-attach if deps change
150150

151-
// Handle Zoom (Wheel)
152-
const handleWheel = (e: React.WheelEvent) => {
153-
if (e.ctrlKey || e.metaKey) {
154-
e.preventDefault();
155-
const delta = -e.deltaY;
156-
setZoomLevel(prev => Math.max(1, Math.min(10, prev + delta * 0.001)));
157-
}
158-
};
151+
// Handle Zoom (Wheel) - Non-passive listener to prevent page zoom
152+
useEffect(() => {
153+
const container = containerRef.current;
154+
if (!container) return;
155+
156+
const onWheel = (e: WheelEvent) => {
157+
if (e.ctrlKey || e.metaKey) {
158+
e.preventDefault();
159+
const delta = -e.deltaY;
160+
setZoomLevel(prev => Math.max(1, Math.min(10, prev + delta * 0.01))); // Increased sensitivity slightly
161+
}
162+
};
163+
164+
container.addEventListener('wheel', onWheel, { passive: false });
165+
// Also handle gesture events for Safari if needed (gesturestart/change/end) logic could go here
166+
167+
return () => {
168+
container.removeEventListener('wheel', onWheel);
169+
};
170+
}, []);
159171

160172
// Trim handle dragging
161173
const handleHandleMouseDown = (handle: 'start' | 'end') => (e: React.MouseEvent) => {
@@ -288,7 +300,7 @@ export const VideoTimeline = ({
288300
onMouseMove={handleMouseMove}
289301
onMouseUp={handleMouseUp}
290302
onMouseLeave={handleMouseLeave}
291-
onWheel={handleWheel}
303+
// onWheel removed - handled by non-passive ref listener
292304
onScroll={(e) => setScrollLeft(e.currentTarget.scrollLeft)}
293305
>
294306
{/* Scrollable Content */}

0 commit comments

Comments
 (0)