Skip to content

🎥 Make videos programmatically with React

nice indicators

Jonny Burger80431ec46434
diff --git a/packages/cli/src/editor/components/Timeline/Timeline.tsx b/packages/cli/src/editor/components/Timeline/Timeline.tsx
index 6ca079902a..9373c9c824 100644
--- a/packages/cli/src/editor/components/Timeline/Timeline.tsx
+++ b/packages/cli/src/editor/components/Timeline/Timeline.tsx
@@ -28,6 +28,7 @@ import {TimelineList} from './TimelineList';
import {TimelinePlayCursorSyncer} from './TimelinePlayCursorSyncer';
import {TimelineScrollable} from './TimelineScrollable';
import {TimelineSlider} from './TimelineSlider';
+import {TIMELINE_TIME_INDICATOR_HEIGHT} from './TimelineTimeIndicators';
import {TimelineTracks} from './TimelineTracks';
const container: React.CSSProperties = {
@@ -87,7 +88,8 @@ export const Timeline: React.FC = () => {
return {
height:
shown.length * (TIMELINE_LAYER_HEIGHT + TIMELINE_BORDER * 2) +
- (hasBeenCut ? MAX_TIMELINE_TRACKS_NOTICE_HEIGHT : 0),
+ (hasBeenCut ? MAX_TIMELINE_TRACKS_NOTICE_HEIGHT : 0) +
+ TIMELINE_TIME_INDICATOR_HEIGHT,
display: 'flex',
flex: 1,
minHeight: '100%',
diff --git a/packages/cli/src/editor/components/Timeline/TimelineList.tsx b/packages/cli/src/editor/components/Timeline/TimelineList.tsx
index 525a99661d..23be58afb9 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineList.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineList.tsx
@@ -7,6 +7,10 @@ import type {
TimelineViewState,
} from './timeline-state-reducer';
import {TimelineListItem} from './TimelineListItem';
+import {
+ TimelineTimePadding,
+ TimelineTimePlaceholders,
+} from './TimelineTimeIndicators';
const container: React.CSSProperties = {
flex: 1,
@@ -22,6 +26,8 @@ export const TimelineList: React.FC<{
}> = ({timeline, viewState, dispatchStateChange}) => {
return (
<div style={container}>
+ <TimelineTimePadding />
+
{timeline.map((track, i) => {
const beforeDepth = i === 0 ? 0 : timeline[i - 1].depth;
@@ -40,6 +46,7 @@ export const TimelineList: React.FC<{
</div>
);
})}
+ <TimelineTimePlaceholders />
</div>
);
};
diff --git a/packages/cli/src/editor/components/Timeline/TimelineTimeIndicators.tsx b/packages/cli/src/editor/components/Timeline/TimelineTimeIndicators.tsx
new file mode 100644
index 0000000000..39b1d9d02b
--- /dev/null
+++ b/packages/cli/src/editor/components/Timeline/TimelineTimeIndicators.tsx
@@ -0,0 +1,99 @@
+import {PlayerInternals} from '@remotion/player';
+import React, {useEffect, useRef} from 'react';
+import {sliderAreaRef, timelineVerticalScroll} from './timeline-refs';
+
+export const TIMELINE_TIME_INDICATOR_HEIGHT = 45;
+
+export const TimelineTimePlaceholders: React.FC = () => {
+ const ref = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ const currentRef = ref.current;
+ if (!currentRef) {
+ return;
+ }
+
+ const {current} = timelineVerticalScroll;
+ if (!current) {
+ return;
+ }
+
+ const onScroll = () => {
+ currentRef.style.top = current.scrollTop + 'px';
+ };
+
+ current.addEventListener('scroll', onScroll);
+ return () => {
+ current.removeEventListener('scroll', onScroll);
+ };
+ }, []);
+
+ return (
+ <div
+ ref={ref}
+ style={{
+ height: TIMELINE_TIME_INDICATOR_HEIGHT,
+ backgroundColor: 'green',
+ position: 'absolute',
+ top: 0,
+ width: '100%',
+ }}
+ />
+ );
+};
+
+export const TimelineTimePadding: React.FC = () => {
+ return (
+ <div
+ style={{
+ height: TIMELINE_TIME_INDICATOR_HEIGHT,
+ }}
+ />
+ );
+};
+
+export const TimelineTimeIndicators: React.FC = () => {
+ const size = PlayerInternals.useElementSize(sliderAreaRef, {
+ triggerOnWindowResize: false,
+ shouldApplyCssTransforms: true,
+ });
+
+ const windowWidth = size?.width ?? 0;
+
+ const ref = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ const currentRef = ref.current;
+ if (!currentRef) {
+ return;
+ }
+
+ const {current} = timelineVerticalScroll;
+ if (!current) {
+ return;
+ }
+
+ const onScroll = () => {
+ currentRef.style.top = current.scrollTop + 'px';
+ };
+
+ current.addEventListener('scroll', onScroll);
+ return () => {
+ current.removeEventListener('scroll', onScroll);
+ };
+ }, []);
+
+ return (
+ <div
+ ref={ref}
+ // TODO: Remove inline styles in this file
+ style={{
+ height: TIMELINE_TIME_INDICATOR_HEIGHT,
+ backgroundColor: 'yellow',
+ width: windowWidth,
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ }}
+ />
+ );
+};
diff --git a/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx b/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx
index 486c8c65fd..ee27ad47ca 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineTracks.tsx
@@ -9,6 +9,10 @@ import {isTrackHidden} from './is-collapsed';
import {MaxTimelineTracksReached} from './MaxTimelineTracks';
import type {TimelineViewState} from './timeline-state-reducer';
import {TimelineSequence} from './TimelineSequence';
+import {
+ TimelineTimeIndicators,
+ TimelineTimePadding,
+} from './TimelineTimeIndicators';
const content: React.CSSProperties = {
paddingLeft: TIMELINE_PADDING,
@@ -41,6 +45,7 @@ export const TimelineTracks: React.FC<{
return (
<div style={timelineStyle}>
<div style={content}>
+ <TimelineTimePadding />
{timeline.map((track) => {
if (isTrackHidden(track, timeline, viewState)) {
return null;
@@ -52,6 +57,7 @@ export const TimelineTracks: React.FC<{
</div>
);
})}
+ <TimelineTimeIndicators />
</div>
{hasBeenCut ? <MaxTimelineTracksReached /> : null}
</div>