🎥 Make videos programmatically with React
Share collapse state across compact timeline scene rows
Jonny Burger78e968fa20ac
diff --git a/packages/studio/src/components/Timeline/Timeline.tsx b/packages/studio/src/components/Timeline/Timeline.tsxindex d1f5225b49..cb22f38a26 100644--- a/packages/studio/src/components/Timeline/Timeline.tsx+++ b/packages/studio/src/components/Timeline/Timeline.tsx@@ -436,6 +436,7 @@ const TimelineInner: React.FC = () => {collapsed,sequences,canvasContent?.type === 'composition' ? canvasContent.compositionId : null,+ compactSeries,);const {fastRefreshes} = useContext(FastRefreshContext);const pendingSelectionStart = useRef<{diff --git a/packages/studio/src/components/Timeline/TimelineLayerChildren.tsx b/packages/studio/src/components/Timeline/TimelineLayerChildren.tsxindex e83027df19..0bea03e1fd 100644--- a/packages/studio/src/components/Timeline/TimelineLayerChildren.tsx+++ b/packages/studio/src/components/Timeline/TimelineLayerChildren.tsx@@ -20,6 +20,8 @@ import {import {toggleBooleanMapKey} from '../../helpers/persist-boolean-map';import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';import type {TimelineTrackWithDisplayGroup} from './timeline-display-groups';+import {getTimelineSeriesLayout} from './timeline-series-layout';+import {getTimelineDisplayRows} from './timeline-track-groups';import {TimelineCollapseToggle} from './TimelineCollapseToggle';// Reserve the same space before and after children register or unregister.@@ -49,6 +51,7 @@ export const useTimelineLayerChildren = (tracks: TimelineTrackWithDisplayGroup[],sequences: TSequence[],compositionId: string | null,+ compactSeries: boolean,) => {const [collapsed, setCollapsed] = useState<Record<string, boolean>>(() => {try {@@ -91,6 +94,7 @@ export const useTimelineLayerChildren = (}const keys = new Map<string, string>();+ const identities = new Map<string, string>();const parents = new Set<string>();const ancestors = new Map<string, string[]>();for (const track of tracks) {@@ -116,15 +120,58 @@ export const useTimelineLayerChildren = (.concat(track.sequence.id).map((id) => siblingIndices.get(id)),];+ const key = JSON.stringify([compositionId, identity]);+ identities.set(track.sequence.id, key);// Packed clips have no child-collapse control. Do not let a saved// layer collapse make an explicit nested Track inaccessible.if (!track.sequence.timelineTrack) {- keys.set(track.sequence.id, JSON.stringify([compositionId, identity]));+ keys.set(track.sequence.id, key);+ }+ }++ if (compactSeries) {+ const rows = getTimelineDisplayRows(tracks);+ // Use structural row positions before hiding children. Expanding fields+ // or collapsing a layer must not change which layers share its state.+ const layout = getTimelineSeriesLayout({+ rows,+ heights: rows.map(() => 1),+ sequences,+ compactSeries,+ paddingStart: 0,+ });+ for (let index = 0; index < rows.length; index++) {+ const position = layout.sharedChildPositions[index];+ if (position === null) {+ continue;+ }++ const {sequence} = rows[index].track;+ if (!keys.has(sequence.id)) {+ continue;+ }++ const seriesKey = identities.get(+ rows[position.seriesIndex].track.sequence.id,+ );+ if (seriesKey === undefined) {+ continue;+ }++ keys.set(+ sequence.id,+ JSON.stringify([+ 'series-row',+ seriesKey,+ position.role,+ position.offset,+ ]),+ );}}return {keys, parents, ancestors};- }, [compositionId, sequences, tracks]);+ }, [compactSeries, compositionId, sequences, tracks]);const visibleTracks = useMemo(() =>tracks.filter((track) => {diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsxindex e62b6fa74d..7fbb8244ae 100644--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx@@ -544,7 +544,7 @@ const TimelineSequenceBar: React.FC<{</svg>)}- {s.timelineTrack ? (+ {s.timelineTrack && s.timelineTrack.role !== 'transition' ? (<divstyle={{position: 'absolute',diff --git a/packages/studio/src/components/Timeline/timeline-series-layout.ts b/packages/studio/src/components/Timeline/timeline-series-layout.tsindex 9fde5e5d2c..2febb86a44 100644--- a/packages/studio/src/components/Timeline/timeline-series-layout.ts+++ b/packages/studio/src/components/Timeline/timeline-series-layout.ts@@ -106,6 +106,11 @@ export const getTimelineSeriesLayout = ({null,);const groupIndexes = new Array<number>(rows.length);+ const sharedChildPositions = new Array<{+ readonly seriesIndex: number;+ readonly role: 'clip' | 'overlay';+ readonly offset: number;+ } | null>(rows.length).fill(null);const groups: {readonly index: number;readonly rows: number[];@@ -191,6 +196,14 @@ export const getTimelineSeriesLayout = ({for (const placement of placements) {for (const childIndex of placement.rows) {+ // A scene can move between lanes as neighboring scenes mount.+ // Its child-collapse identity follows its position within the+ // scene, independently of the lane used for an overlap.+ sharedChildPositions[childIndex] ??= {+ seriesIndex: index,+ role,+ offset: offsets[childIndex] - cursor,+ };offsets[childIndex] += placement.lane * laneHeight;}}@@ -243,6 +256,7 @@ export const getTimelineSeriesLayout = ({sceneRanges,groupIndexes,groups,+ sharedChildPositions,tracksEnd,siblingIndexes,afterDropLineOffsets: subtreeEnds.map((end, index) => end - offsets[index]),