Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Consolidate timeline `showInTimeline` filtering

Jonny Burger8079340cc6fc
diff --git a/packages/studio/src/components/Timeline/Timeline.tsx b/packages/studio/src/components/Timeline/Timeline.tsx
index c5acf4abef..bd6574a659 100644
--- a/packages/studio/src/components/Timeline/Timeline.tsx
+++ b/packages/studio/src/components/Timeline/Timeline.tsx
@@ -8,9 +8,9 @@ import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';
import {SplitterContainer} from '../Splitter/SplitterContainer';
import {SplitterElement} from '../Splitter/SplitterElement';
import {SplitterHandle} from '../Splitter/SplitterHandle';
-import {isTrackHidden} from './is-collapsed';
import {MAX_TIMELINE_TRACKS} from './MaxTimelineTracks';
import {SequencePropsObserver} from './SequencePropsObserver';
+import {shouldShowTrackInTimeline} from './should-show-track-in-timeline';
import {SubscribeToNodePaths} from './SubscribeToNodePaths';
import {timelineVerticalScroll} from './timeline-refs';
import {TimelineDragHandler} from './TimelineDragHandler';
@@ -66,12 +66,8 @@ const TimelineInner: React.FC = () => {
const durationInFrames = videoConfig?.durationInFrames ?? 0;
const filtered = useMemo(() => {
- return timeline.filter(
- (t) =>
- !isTrackHidden(t) &&
- t.sequence.from <= durationInFrames &&
- t.sequence.duration > 0 &&
- t.sequence.showInTimeline,
+ return timeline.filter((t) =>
+ shouldShowTrackInTimeline(t, durationInFrames),
);
}, [durationInFrames, timeline]);
diff --git a/packages/studio/src/components/Timeline/TimelineTracks.tsx b/packages/studio/src/components/Timeline/TimelineTracks.tsx
index 92ea99a0ab..cecf4648cd 100644
--- a/packages/studio/src/components/Timeline/TimelineTracks.tsx
+++ b/packages/studio/src/components/Timeline/TimelineTracks.tsx
@@ -16,7 +16,6 @@ import {
ExpandedTracksGetterContext,
type GetIsExpanded,
} from '../ExpandedTracksProvider';
-import {isTrackHidden} from './is-collapsed';
import {MaxTimelineTracksReached} from './MaxTimelineTracks';
import {TimelineSequence} from './TimelineSequence';
import {TimelineTimePadding} from './TimelineTimeIndicators';
@@ -73,10 +72,6 @@ const TimelineTracksInner: React.FC<{
<div style={content}>
<TimelineTimePadding />
{timeline.map((track) => {
- if (isTrackHidden(track)) {
- return null;
- }
-
const isExpanded =
track.nodePathInfo !== null && getIsExpanded(track.nodePathInfo);
diff --git a/packages/studio/src/components/Timeline/is-collapsed.ts b/packages/studio/src/components/Timeline/is-collapsed.ts
deleted file mode 100644
index bd9aed71c2..0000000000
--- a/packages/studio/src/components/Timeline/is-collapsed.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
-
-export const isTrackHidden = (track: TrackWithHash): boolean => {
- if (!track.sequence.parent) {
- return false;
- }
-
- return !track.sequence.showInTimeline;
-};
diff --git a/packages/studio/src/components/Timeline/should-show-track-in-timeline.ts b/packages/studio/src/components/Timeline/should-show-track-in-timeline.ts
new file mode 100644
index 0000000000..f95d32f8da
--- /dev/null
+++ b/packages/studio/src/components/Timeline/should-show-track-in-timeline.ts
@@ -0,0 +1,27 @@
+import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
+
+// A track is shown in the timeline list when:
+// - The sequence opted-in via `showInTimeline` (the default).
+// Children of a sequence with `showInTimeline: false` keep being listed
+// on their own; their depth is independently flattened by
+// `getTimelineNestedLevel` so the parent does not contribute an indent.
+// - The sequence has a positive duration.
+// - The sequence starts before the composition ends.
+export const shouldShowTrackInTimeline = (
+ track: TrackWithHash,
+ durationInFrames: number,
+): boolean => {
+ if (!track.sequence.showInTimeline) {
+ return false;
+ }
+
+ if (track.sequence.duration <= 0) {
+ return false;
+ }
+
+ if (track.sequence.from > durationInFrames) {
+ return false;
+ }
+
+ return true;
+};