Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Refactor timeline keyframes and tracks layout

Jonny Burgerc149a8aacee6
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsx
new file mode 100644
index 0000000000..840ed55378
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineExpandedKeyframeRow.tsx
@@ -0,0 +1,49 @@
+import React from 'react';
+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
+import {TIMELINE_ITEM_BORDER_BOTTOM} from '../../helpers/timeline-layout';
+import type {getTimelineKeyframes} from './get-timeline-keyframes';
+import {TimelineKeyframeDiamond} from './TimelineKeyframeDiamond';
+import {
+ TIMELINE_SELECTED_TRACK_HIGHLIGHT_STYLE,
+ useTimelineRowSelection,
+} from './TimelineSelection';
+
+const row: React.CSSProperties = {
+ position: 'relative',
+};
+
+const rowSeparator: React.CSSProperties = {
+ height: TIMELINE_ITEM_BORDER_BOTTOM,
+};
+
+const TimelineExpandedKeyframeRowUnmemoized: React.FC<{
+ readonly height: number;
+ readonly keyframes: ReturnType<typeof getTimelineKeyframes>;
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly showSeparator: boolean;
+}> = ({height, keyframes, nodePathInfo, showSeparator}) => {
+ const {selected: rowSelected} = useTimelineRowSelection(nodePathInfo);
+
+ return (
+ <>
+ {showSeparator ? <div style={rowSeparator} /> : null}
+ <div style={{...row, height}}>
+ {rowSelected ? (
+ <div style={TIMELINE_SELECTED_TRACK_HIGHLIGHT_STYLE} />
+ ) : null}
+ {keyframes.map((keyframe) => (
+ <TimelineKeyframeDiamond
+ key={keyframe.frame}
+ frame={keyframe.frame}
+ rowHeight={height}
+ nodePathInfo={nodePathInfo}
+ />
+ ))}
+ </div>
+ </>
+ );
+};
+
+export const TimelineExpandedKeyframeRow = React.memo(
+ TimelineExpandedKeyframeRowUnmemoized,
+);
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx b/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx
index e4ab72e76f..433fe15052 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx
@@ -1,210 +1,31 @@
-import React, {useContext, useMemo} from 'react';
-import {Internals, useVideoConfig, type TSequence} from 'remotion';
-import {LIGHT_TEXT} from '../../helpers/colors';
-import {getXPositionOfItemInTimelineImperatively} from '../../helpers/get-left-of-timeline-slider';
+import React from 'react';
+import type {TSequence} from 'remotion';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
-import {
- buildTimelineTree,
- flattenVisibleTreeNodes,
- getExpandedTrackHeight,
- getTreeRowHeight,
- TIMELINE_ITEM_BORDER_BOTTOM,
- TIMELINE_PADDING,
-} from '../../helpers/timeline-layout';
-import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
-import {getTimelineKeyframes} from './get-timeline-keyframes';
-import {
- getTimelineSelectedTrackHighlightStyle,
- TIMELINE_SELECTED_LABEL_BACKGROUND,
- useTimelineSelection,
- type TimelineSelection,
-} from './TimelineSelection';
-import {TimelineWidthContext} from './TimelineWidthProvider';
-
-const row: React.CSSProperties = {
- position: 'relative',
-};
-
-const rowSeparator: React.CSSProperties = {
- height: TIMELINE_ITEM_BORDER_BOTTOM,
-};
-
-const diamondBase: React.CSSProperties = {
- position: 'absolute',
- width: 8,
- height: 8,
- backgroundColor: LIGHT_TEXT,
- borderRadius: 1,
- boxShadow: '0 0 0 1px rgba(0, 0, 0, 0.4)',
- pointerEvents: 'none',
-};
-
-const getNodeKeyframes = ({
- node,
- nodePath,
- codeValues,
- keyframeDisplayOffset,
-}: {
- node: ReturnType<typeof flattenVisibleTreeNodes>[number]['node'];
- nodePath: SequenceNodePathInfo['sequenceSubscriptionKey'];
- codeValues: React.ContextType<
- typeof Internals.VisualModeCodeValuesContext
- >['codeValues'];
- keyframeDisplayOffset: number;
-}): ReturnType<typeof getTimelineKeyframes> => {
- if (node.kind !== 'field' || node.field === null) {
- return [];
- }
-
- if (node.field.kind === 'sequence-field') {
- return getTimelineKeyframes(
- Internals.getCodeValuesCtx(codeValues, nodePath)?.[node.field.key],
- keyframeDisplayOffset,
- );
- }
-
- const effectStatus = Internals.getEffectCodeValuesCtx({
- codeValues,
- nodePath,
- effectIndex: node.field.effectIndex,
- });
-
- return getTimelineKeyframes(
- effectStatus.type === 'can-update-effect'
- ? effectStatus.props?.[node.field.key]
- : null,
- keyframeDisplayOffset,
- );
-};
+import {TimelineExpandedKeyframeRow} from './TimelineExpandedKeyframeRow';
+import {useExpandedTrackKeyframeRows} from './use-expanded-track-keyframe-rows';
const TimelineExpandedTrackKeyframesInner: React.FC<{
readonly sequence: TSequence;
readonly nodePathInfo: SequenceNodePathInfo;
readonly keyframeDisplayOffset: number;
}> = ({nodePathInfo, sequence, keyframeDisplayOffset}) => {
- const videoConfig = useVideoConfig();
- const timelineWidth = useContext(TimelineWidthContext);
- const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
- const {codeValues} = useContext(Internals.VisualModeCodeValuesContext);
- const {isSelected, selectItem} = useTimelineSelection();
-
- const tree = useMemo(
- () =>
- buildTimelineTree({
- sequence,
- nodePathInfo,
- getDragOverrides: () => ({}),
- getEffectDragOverrides: () => ({}),
- codeValues,
- }),
- [codeValues, nodePathInfo, sequence],
- );
-
- const flat = useMemo(
- () => flattenVisibleTreeNodes({nodes: tree, getIsExpanded}),
- [tree, getIsExpanded],
- );
-
- const expandedHeight = useMemo(
- () =>
- getExpandedTrackHeight({
- sequence,
- nodePathInfo,
- getIsExpanded,
- codeValues,
- }),
- [codeValues, getIsExpanded, nodePathInfo, sequence],
- );
-
- const rows = useMemo(
- () =>
- flat.map(({node}) => ({
- height: getTreeRowHeight(node),
- keyframes: getNodeKeyframes({
- node,
- nodePath: nodePathInfo.sequenceSubscriptionKey,
- codeValues,
- keyframeDisplayOffset,
- }),
- key: JSON.stringify(node.nodePathInfo),
- rowNodePathInfo: node.nodePathInfo,
- })),
- [
- codeValues,
- flat,
- keyframeDisplayOffset,
- nodePathInfo.sequenceSubscriptionKey,
- ],
- );
+ const {rows, expandedHeight} = useExpandedTrackKeyframeRows({
+ sequence,
+ nodePathInfo,
+ keyframeDisplayOffset,
+ });
return (
- <div
- style={{
- height: expandedHeight,
- }}
- >
- <div style={{height: expandedHeight}}>
- {rows.map(({height, keyframes, key, rowNodePathInfo}, i) => {
- const rowSelected = isSelected({
- type: 'row',
- nodePathInfo: rowNodePathInfo,
- });
-
- return (
- <React.Fragment key={key}>
- {i > 0 ? <div style={rowSeparator} /> : null}
- <div style={{...row, height}}>
- {rowSelected ? (
- <div style={getTimelineSelectedTrackHighlightStyle()} />
- ) : null}
- {timelineWidth === null
- ? null
- : keyframes.map((keyframe) => {
- const selectionItem: TimelineSelection = {
- type: 'keyframe',
- nodePathInfo: rowNodePathInfo,
- frame: keyframe.frame,
- };
- const selected = isSelected(selectionItem);
-
- return (
- <button
- key={String(keyframe.frame)}
- type="button"
- style={{
- ...diamondBase,
- backgroundColor: selected
- ? TIMELINE_SELECTED_LABEL_BACKGROUND
- : LIGHT_TEXT,
- border: 'none',
- cursor: 'default',
- left:
- getXPositionOfItemInTimelineImperatively(
- keyframe.frame,
- videoConfig.durationInFrames,
- timelineWidth,
- ) - TIMELINE_PADDING,
- padding: 0,
- pointerEvents: 'auto',
- top: height / 2,
- transform: 'translate(-50%, -50%) rotate(45deg)',
- }}
- title={`Keyframe at frame ${keyframe.frame}`}
- aria-label={`Select keyframe at frame ${keyframe.frame}`}
- onPointerDown={(e) => {
- if (e.button === 0) {
- e.stopPropagation();
- selectItem(selectionItem);
- }
- }}
- />
- );
- })}
- </div>
- </React.Fragment>
- );
- })}
- </div>
+ <div style={{height: expandedHeight}}>
+ {rows.map((row, index) => (
+ <TimelineExpandedKeyframeRow
+ key={row.rowKey}
+ height={row.height}
+ keyframes={row.keyframes}
+ nodePathInfo={row.nodePathInfo}
+ showSeparator={index > 0}
+ />
+ ))}
</div>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsx
new file mode 100644
index 0000000000..03260a8635
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineKeyframeDiamond.tsx
@@ -0,0 +1,87 @@
+import React, {useCallback, useContext, useMemo} from 'react';
+import {useVideoConfig} from 'remotion';
+import {LIGHT_TEXT} from '../../helpers/colors';
+import {getXPositionOfItemInTimelineImperatively} from '../../helpers/get-left-of-timeline-slider';
+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
+import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
+import {
+ TIMELINE_SELECTED_LABEL_BACKGROUND,
+ useTimelineKeyframeSelection,
+} from './TimelineSelection';
+import {TimelineWidthContext} from './TimelineWidthProvider';
+
+const diamondBase: React.CSSProperties = {
+ position: 'absolute',
+ width: 8,
+ height: 8,
+ backgroundColor: LIGHT_TEXT,
+ borderRadius: 1,
+ boxShadow: '0 0 0 1px rgba(0, 0, 0, 0.4)',
+ pointerEvents: 'none',
+};
+
+const TimelineKeyframeDiamondUnmemoized: React.FC<{
+ readonly frame: number;
+ readonly rowHeight: number;
+ readonly nodePathInfo: SequenceNodePathInfo;
+}> = ({frame, rowHeight, nodePathInfo}) => {
+ const videoConfig = useVideoConfig();
+ const timelineWidth = useContext(TimelineWidthContext);
+ const {selected, onSelect, selectable} = useTimelineKeyframeSelection(
+ nodePathInfo,
+ frame,
+ );
+
+ const style = useMemo((): React.CSSProperties | null => {
+ if (timelineWidth === null) {
+ return null;
+ }
+
+ return {
+ ...diamondBase,
+ backgroundColor: selected
+ ? TIMELINE_SELECTED_LABEL_BACKGROUND
+ : LIGHT_TEXT,
+ border: 'none',
+ cursor: 'default',
+ left:
+ getXPositionOfItemInTimelineImperatively(
+ frame,
+ videoConfig.durationInFrames,
+ timelineWidth,
+ ) - TIMELINE_PADDING,
+ padding: 0,
+ pointerEvents: 'auto',
+ top: rowHeight / 2,
+ transform: 'translate(-50%, -50%) rotate(45deg)',
+ };
+ }, [frame, rowHeight, selected, timelineWidth, videoConfig.durationInFrames]);
+
+ const onPointerDown = useCallback(
+ (e: React.PointerEvent<HTMLButtonElement>) => {
+ if (e.button === 0) {
+ e.stopPropagation();
+ onSelect();
+ }
+ },
+ [onSelect],
+ );
+
+ if (style === null) {
+ return null;
+ }
+
+ return (
+ <button
+ type="button"
+ style={style}
+ title={`Keyframe at frame ${frame}`}
+ aria-label={`Select keyframe at frame ${frame}`}
+ onPointerDown={selectable ? onPointerDown : undefined}
+ />
+ );
+};
+
+export const TimelineKeyframeDiamond = React.memo(
+ TimelineKeyframeDiamondUnmemoized,
+);
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index 7c78bafeb9..067254201c 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -41,7 +41,7 @@ export const getTimelineColor = (selected: boolean, subcategory: boolean) => {
: 'rgba(255, 255, 255, 0.8)';
};
-export const getTimelineSelectedTrackHighlightStyle = (): CSSProperties => ({
+export const TIMELINE_SELECTED_TRACK_HIGHLIGHT_STYLE: CSSProperties = {
backgroundColor: TIMELINE_SELECTED_BACKGROUND,
bottom: 0,
left: -TIMELINE_PADDING,
@@ -49,7 +49,7 @@ export const getTimelineSelectedTrackHighlightStyle = (): CSSProperties => ({
position: 'absolute',
right: -TIMELINE_PADDING,
top: 0,
-});
+};
export const SELECTION_ENABLED = true;
@@ -218,6 +218,33 @@ export const useTimelineRowSelection = (
};
};
+export const useTimelineKeyframeSelection = (
+ nodePathInfo: SequenceNodePathInfo,
+ frame: number,
+) => {
+ const {canSelect, isSelected, selectItem} = useTimelineSelection();
+ const selectionItem = useMemo(
+ (): TimelineSelection => ({
+ type: 'keyframe',
+ nodePathInfo,
+ frame,
+ }),
+ [nodePathInfo, frame],
+ );
+
+ const selected = isSelected(selectionItem);
+
+ const onSelect = useCallback(() => {
+ selectItem(selectionItem);
+ }, [selectItem, selectionItem]);
+
+ return {
+ onSelect,
+ selectable: canSelect,
+ selected,
+ };
+};
+
export const useTimelineRowContainsSelection = (
nodePathInfo: SequenceNodePathInfo | null,
): boolean => {
diff --git a/packages/studio/src/components/Timeline/TimelineTrack.tsx b/packages/studio/src/components/Timeline/TimelineTrack.tsx
new file mode 100644
index 0000000000..df20ed962e
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineTrack.tsx
@@ -0,0 +1,62 @@
+import React, {useContext, useMemo} from 'react';
+import {StudioServerConnectionCtx} from '../../helpers/client-id';
+import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
+import {
+ getTimelineLayerHeight,
+ TIMELINE_ITEM_BORDER_BOTTOM,
+} from '../../helpers/timeline-layout';
+import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
+import {TimelineExpandedTrackKeyframes} from './TimelineExpandedTrackKeyframes';
+import {
+ TIMELINE_SELECTED_TRACK_HIGHLIGHT_STYLE,
+ useTimelineRowContainsSelection,
+ useTimelineRowSelection,
+} from './TimelineSelection';
+import {TimelineSequence} from './TimelineSequence';
+
+const TimelineTrackUnmemoized: React.FC<{
+ readonly track: TrackWithHash;
+}> = ({track}) => {
+ const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const previewServerConnected = previewServerState.type === 'connected';
+ const {selected: rowSelected} = useTimelineRowSelection(track.nodePathInfo);
+ const containsSelection = useTimelineRowContainsSelection(track.nodePathInfo);
+
+ const layerStyle = useMemo(
+ (): React.CSSProperties => ({
+ height: getTimelineLayerHeight(track.sequence.type),
+ marginBottom: TIMELINE_ITEM_BORDER_BOTTOM,
+ position: 'relative',
+ }),
+ [track.sequence.type],
+ );
+
+ const showExpandedKeyframes =
+ track.nodePathInfo !== null &&
+ previewServerConnected &&
+ getIsExpanded(track.nodePathInfo);
+
+ const showRowHighlight =
+ track.nodePathInfo !== null && (rowSelected || containsSelection);
+
+ return (
+ <div>
+ <div style={layerStyle}>
+ {showRowHighlight ? (
+ <div style={TIMELINE_SELECTED_TRACK_HIGHLIGHT_STYLE} />
+ ) : null}
+ <TimelineSequence s={track.sequence} />
+ </div>
+ {showExpandedKeyframes && track.nodePathInfo ? (
+ <TimelineExpandedTrackKeyframes
+ sequence={track.sequence}
+ nodePathInfo={track.nodePathInfo}
+ keyframeDisplayOffset={track.keyframeDisplayOffset}
+ />
+ ) : null}
+ </div>
+ );
+};
+
+export const TimelineTrack = React.memo(TimelineTrackUnmemoized);
diff --git a/packages/studio/src/components/Timeline/TimelineTracks.tsx b/packages/studio/src/components/Timeline/TimelineTracks.tsx
index 62d304678e..415b7c931f 100644
--- a/packages/studio/src/components/Timeline/TimelineTracks.tsx
+++ b/packages/studio/src/components/Timeline/TimelineTracks.tsx
@@ -1,20 +1,9 @@
-import React, {useContext, useMemo} from 'react';
-import {StudioServerConnectionCtx} from '../../helpers/client-id';
+import React, {useMemo} from 'react';
import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
-import {
- getTimelineLayerHeight,
- TIMELINE_ITEM_BORDER_BOTTOM,
- TIMELINE_PADDING,
-} from '../../helpers/timeline-layout';
-import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
+import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
import {MaxTimelineTracksReached} from './MaxTimelineTracks';
-import {TimelineExpandedTrackKeyframes} from './TimelineExpandedTrackKeyframes';
-import {
- getTimelineSelectedTrackHighlightStyle,
- useTimelineSelection,
-} from './TimelineSelection';
-import {TimelineSequence} from './TimelineSequence';
import {TimelineTimePadding} from './TimelineTimeIndicators';
+import {TimelineTrack} from './TimelineTrack';
const content: React.CSSProperties = {
paddingLeft: TIMELINE_PADDING,
@@ -29,11 +18,6 @@ const TimelineTracksInner: React.FC<{
readonly timeline: TrackWithHash[];
readonly hasBeenCut: boolean;
}> = ({timeline, hasBeenCut}) => {
- const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
- const {previewServerState} = useContext(StudioServerConnectionCtx);
- const previewServerConnected = previewServerState.type === 'connected';
- const {isSelected, containsSelection} = useTimelineSelection();
-
const timelineStyle: React.CSSProperties = useMemo(() => {
return {
...timelineContent,
@@ -45,38 +29,9 @@ const TimelineTracksInner: React.FC<{
<div style={timelineStyle}>
<div style={content}>
<TimelineTimePadding />
- {timeline.map((track) => {
- const isExpanded =
- track.nodePathInfo !== null && getIsExpanded(track.nodePathInfo);
- const rowSelected =
- track.nodePathInfo !== null &&
- (isSelected({type: 'row', nodePathInfo: track.nodePathInfo}) ||
- containsSelection(track.nodePathInfo));
-
- return (
- <div key={track.sequence.id}>
- <div
- style={{
- height: getTimelineLayerHeight(track.sequence.type),
- marginBottom: TIMELINE_ITEM_BORDER_BOTTOM,
- position: 'relative',
- }}
- >
- {rowSelected ? (
- <div style={getTimelineSelectedTrackHighlightStyle()} />
- ) : null}
- <TimelineSequence s={track.sequence} />
- </div>
- {isExpanded && track.nodePathInfo && previewServerConnected ? (
- <TimelineExpandedTrackKeyframes
- sequence={track.sequence}
- nodePathInfo={track.nodePathInfo}
- keyframeDisplayOffset={track.keyframeDisplayOffset}
- />
- ) : null}
- </div>
- );
- })}
+ {timeline.map((track) => (
+ <TimelineTrack key={track.sequence.id} track={track} />
+ ))}
</div>
{hasBeenCut ? <MaxTimelineTracksReached /> : null}
</div>
diff --git a/packages/studio/src/components/Timeline/get-node-keyframes.ts b/packages/studio/src/components/Timeline/get-node-keyframes.ts
new file mode 100644
index 0000000000..7be80bfdeb
--- /dev/null
+++ b/packages/studio/src/components/Timeline/get-node-keyframes.ts
@@ -0,0 +1,43 @@
+import {
+ Internals,
+ type CodeValues,
+ type SequencePropsSubscriptionKey,
+} from 'remotion';
+import type {TimelineTreeNode} from '../../helpers/timeline-layout';
+import {getTimelineKeyframes} from './get-timeline-keyframes';
+
+export const getNodeKeyframes = ({
+ node,
+ nodePath,
+ codeValues,
+ keyframeDisplayOffset,
+}: {
+ node: TimelineTreeNode;
+ nodePath: SequencePropsSubscriptionKey;
+ codeValues: CodeValues;
+ keyframeDisplayOffset: number;
+}): ReturnType<typeof getTimelineKeyframes> => {
+ if (node.kind !== 'field' || node.field === null) {
+ return [];
+ }
+
+ if (node.field.kind === 'sequence-field') {
+ return getTimelineKeyframes(
+ Internals.getCodeValuesCtx(codeValues, nodePath)?.[node.field.key],
+ keyframeDisplayOffset,
+ );
+ }
+
+ const effectStatus = Internals.getEffectCodeValuesCtx({
+ codeValues,
+ nodePath,
+ effectIndex: node.field.effectIndex,
+ });
+
+ return getTimelineKeyframes(
+ effectStatus.type === 'can-update-effect'
+ ? effectStatus.props?.[node.field.key]
+ : null,
+ keyframeDisplayOffset,
+ );
+};
diff --git a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
new file mode 100644
index 0000000000..922bbb01ad
--- /dev/null
+++ b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
@@ -0,0 +1,87 @@
+import {useContext, useMemo} from 'react';
+import {Internals, type TSequence} from 'remotion';
+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
+import {
+ buildTimelineTree,
+ flattenVisibleTreeNodes,
+ getExpandedTrackHeight,
+ getTreeRowHeight,
+} from '../../helpers/timeline-layout';
+import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';
+import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
+import {getNodeKeyframes} from './get-node-keyframes';
+import type {getTimelineKeyframes} from './get-timeline-keyframes';
+
+export type ExpandedTrackKeyframeRow = {
+ readonly height: number;
+ readonly keyframes: ReturnType<typeof getTimelineKeyframes>;
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly rowKey: string;
+};
+
+export const useExpandedTrackKeyframeRows = ({
+ sequence,
+ nodePathInfo,
+ keyframeDisplayOffset,
+}: {
+ sequence: TSequence;
+ nodePathInfo: SequenceNodePathInfo;
+ keyframeDisplayOffset: number;
+}): {
+ readonly rows: ExpandedTrackKeyframeRow[];
+ readonly expandedHeight: number;
+} => {
+ const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
+ const {codeValues} = useContext(Internals.VisualModeCodeValuesContext);
+
+ const tree = useMemo(
+ () =>
+ buildTimelineTree({
+ sequence,
+ nodePathInfo,
+ getDragOverrides: () => ({}),
+ getEffectDragOverrides: () => ({}),
+ codeValues,
+ }),
+ [codeValues, nodePathInfo, sequence],
+ );
+
+ const flat = useMemo(
+ () => flattenVisibleTreeNodes({nodes: tree, getIsExpanded}),
+ [tree, getIsExpanded],
+ );
+
+ const expandedHeight = useMemo(
+ () =>
+ getExpandedTrackHeight({
+ sequence,
+ nodePathInfo,
+ getIsExpanded,
+ codeValues,
+ }),
+ [codeValues, getIsExpanded, nodePathInfo, sequence],
+ );
+
+ const rows = useMemo(
+ (): ExpandedTrackKeyframeRow[] =>
+ flat.map(({node}) => ({
+ height: getTreeRowHeight(node),
+ keyframes: getNodeKeyframes({
+ node,
+ nodePath: nodePathInfo.sequenceSubscriptionKey,
+ codeValues,
+ keyframeDisplayOffset,
+ }),
+ rowKey: timelineNodePathInfoToKey(node.nodePathInfo),
+ nodePathInfo: node.nodePathInfo,
+ })),
+ [
+ codeValues,
+ flat,
+ keyframeDisplayOffset,
+ nodePathInfo.sequenceSubscriptionKey,
+ ],
+ );
+
+ return {rows, expandedHeight};
+};