Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Align timeline playhead with keyframes (#8685)

Jonny Burger3491c9b6accc
diff --git a/packages/studio/src/components/Timeline/TimelineSlider.tsx b/packages/studio/src/components/Timeline/TimelineSlider.tsx
index bb39a35d88..e2bb0f228c 100644
--- a/packages/studio/src/components/Timeline/TimelineSlider.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSlider.tsx
@@ -21,13 +21,35 @@ const container: React.CSSProperties = {
pointerEvents: 'none',
};
+const PLAYHEAD_LINE_WIDTH = 1;
+
const line: React.CSSProperties = {
height: '100vh',
- width: 1,
+ width: PLAYHEAD_LINE_WIDTH,
position: 'fixed',
backgroundColor: '#f02c00',
};
+const PLAYHEAD_CENTER_OFFSET = PLAYHEAD_LINE_WIDTH / 2;
+
+const getTimelineSliderTransform = ({
+ durationInFrames,
+ frame,
+ width,
+}: {
+ durationInFrames: number;
+ frame: number;
+ width: number;
+}) => {
+ const left = getXPositionOfItemInTimelineImperatively(
+ frame,
+ durationInFrames,
+ width,
+ );
+
+ return `translateX(${left - PLAYHEAD_CENTER_OFFSET}px)`;
+};
+
export const redrawTimelineSliderFast = createRef<{
draw: (frame: number, width?: number) => void;
}>();
@@ -66,11 +88,11 @@ const TimelineSliderInner: React.FC = () => {
return;
}
- el.style.transform = `translateX(${getXPositionOfItemInTimelineImperatively(
- timelinePosition,
- videoConfig.durationInFrames,
- measuredWidth,
- )}px)`;
+ el.style.transform = getTimelineSliderTransform({
+ durationInFrames: videoConfig.durationInFrames,
+ frame: timelinePosition,
+ width: measuredWidth,
+ });
}, [
timelinePosition,
videoConfig.durationInFrames,
@@ -86,11 +108,11 @@ const TimelineSliderInner: React.FC = () => {
throw new Error('unexpectedly did not have ref to timelineslider');
}
- current.style.transform = `translateX(${getXPositionOfItemInTimelineImperatively(
+ current.style.transform = getTimelineSliderTransform({
+ durationInFrames: getCurrentDuration(),
frame,
- getCurrentDuration(),
- width ?? (sliderAreaRef.current?.clientWidth as number) ?? 0,
- )}px)`;
+ width: width ?? (sliderAreaRef.current?.clientWidth as number) ?? 0,
+ });
},
};
}, []);