Skip to content

🎥 Make videos programmatically with React

fix nesting in timeline

Jonny Burger1c9ec125fa9d
diff --git a/packages/studio/src/components/Timeline/Padder.tsx b/packages/studio/src/components/Timeline/Padder.tsx
new file mode 100644
index 0000000000..c1eafa392e
--- /dev/null
+++ b/packages/studio/src/components/Timeline/Padder.tsx
@@ -0,0 +1,16 @@
+import React, {useMemo} from 'react';
+import {INDENT} from './TimelineListItem';
+
+export const Padder: React.FC<{
+ readonly depth: number;
+}> = ({depth}) => {
+ const style = useMemo(
+ (): React.CSSProperties => ({
+ width: INDENT * depth,
+ flexShrink: 0,
+ }),
+ [depth],
+ );
+
+ return <div style={style} />;
+};
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
index c43cc2f3a1..86333bd402 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
@@ -9,6 +9,7 @@ import {
getTreeRowHeight,
TREE_GROUP_ROW_HEIGHT,
} from '../../helpers/timeline-layout';
+import {Padder} from './Padder';
import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';
import {TimelineFieldRow} from './TimelineFieldRow';
import {INDENT} from './TimelineListItem';
@@ -35,7 +36,7 @@ const labelOnlyRowBase: React.CSSProperties = {
export const TimelineExpandedRow: React.FC<{
readonly node: TimelineTreeNode;
readonly depth: number;
- readonly sequenceOffsetPx: number;
+ readonly nestedDepth: number;
readonly expandedTracks: Record<string, boolean>;
readonly toggleTrack: (id: string) => void;
readonly overrideId: string;
@@ -45,7 +46,7 @@ export const TimelineExpandedRow: React.FC<{
}> = ({
node,
depth,
- sequenceOffsetPx,
+ nestedDepth,
expandedTracks,
toggleTrack,
overrideId,
@@ -53,8 +54,7 @@ export const TimelineExpandedRow: React.FC<{
nodePath,
schema,
}) => {
- const paddingLeft =
- EXPANDED_SECTION_PADDING_LEFT + depth * INDENT + sequenceOffsetPx;
+ const paddingLeft = EXPANDED_SECTION_PADDING_LEFT + depth * INDENT;
const groupStyle = useMemo(
(): React.CSSProperties => ({...groupRowBase, paddingLeft}),
@@ -74,6 +74,7 @@ export const TimelineExpandedRow: React.FC<{
const isExpanded = expandedTracks[node.id] ?? false;
return (
<div style={groupStyle}>
+ <Padder depth={nestedDepth + 1} />
<TimelineExpandArrowButton
isExpanded={isExpanded}
onClick={() => toggleTrack(node.id)}
@@ -92,6 +93,7 @@ export const TimelineExpandedRow: React.FC<{
overrideId={overrideId}
validatedLocation={validatedLocation}
paddingLeft={paddingLeft}
+ nestedDepth={nestedDepth}
nodePath={nodePath}
schema={schema}
/>
@@ -100,6 +102,7 @@ export const TimelineExpandedRow: React.FC<{
return (
<div style={labelOnlyStyle}>
+ <Padder depth={nestedDepth + 1} />
<span style={rowLabel}>{node.label}</span>
</div>
);
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index e894937a5b..543bb18539 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -13,7 +13,6 @@ import {
} from '../../helpers/timeline-layout';
import {ExpandedTracksContext} from '../ExpandedTracksProvider';
import {TimelineExpandedRow} from './TimelineExpandedRow';
-import {INDENT} from './TimelineListItem';
const expandedSectionBase: React.CSSProperties = {
color: 'white',
@@ -32,9 +31,9 @@ const separator: React.CSSProperties = {
export const TimelineExpandedSection: React.FC<{
readonly sequence: TSequence;
readonly originalLocation: OriginalPosition | null;
- readonly nestedDepth: number;
readonly nodePath: SequenceNodePath | null;
-}> = ({sequence, originalLocation, nestedDepth, nodePath}) => {
+ readonly nestedDepth: number;
+}> = ({sequence, originalLocation, nodePath, nestedDepth}) => {
const {expandedTracks, toggleTrack} = useContext(ExpandedTracksContext);
const {dragOverrides, codeValues} = useContext(
Internals.VisualModeOverridesContext,
@@ -79,8 +78,6 @@ export const TimelineExpandedSection: React.FC<{
[sequence, expandedTracks, dragOverrides, codeValues],
);
- const sequenceOffsetPx = INDENT * nestedDepth;
-
const style = useMemo(() => {
return {
...expandedSectionBase,
@@ -103,7 +100,7 @@ export const TimelineExpandedSection: React.FC<{
<TimelineExpandedRow
node={node}
depth={depth}
- sequenceOffsetPx={sequenceOffsetPx}
+ nestedDepth={nestedDepth}
expandedTracks={expandedTracks}
toggleTrack={toggleTrack}
overrideId={overrideId}
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index 3d2d2f8cbb..d27dd5724a 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -6,6 +6,7 @@ import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-sou
import type {SchemaFieldInfo} from '../../helpers/timeline-layout';
import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';
import {callApi} from '../call-api';
+import {Padder} from './Padder';
import {TimelineFieldValue} from './TimelineSchemaField';
const fieldRowBase: React.CSSProperties = {
@@ -34,6 +35,7 @@ export const TimelineFieldRow: React.FC<{
readonly overrideId: string;
readonly validatedLocation: CodePosition | null;
readonly paddingLeft: number;
+ readonly nestedDepth: number;
readonly nodePath: SequenceNodePath | null;
readonly schema: SequenceSchema;
}> = ({
@@ -41,6 +43,7 @@ export const TimelineFieldRow: React.FC<{
overrideId,
validatedLocation,
paddingLeft,
+ nestedDepth,
nodePath,
schema,
}) => {
@@ -133,6 +136,7 @@ export const TimelineFieldRow: React.FC<{
return (
<div style={style}>
+ <Padder depth={nestedDepth + 1} />
<div style={fieldLabelRow}>
<span style={fieldName}>{field.description ?? field.key}</span>
</div>
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 53cef1f333..a869345837 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -13,6 +13,7 @@ import {ContextMenu} from '../ContextMenu';
import {ExpandedTracksContext} from '../ExpandedTracksProvider';
import type {ComboboxValue} from '../NewComposition/ComboBox';
import {showNotification} from '../Notifications/NotificationCenter';
+import {Padder} from './Padder';
import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';
import {TimelineExpandedSection} from './TimelineExpandedSection';
import {TimelineLayerEye} from './TimelineLayerEye';
@@ -176,13 +177,6 @@ export const TimelineListItem: React.FC<{
toggleTrack(sequence.id);
}, [sequence.id, toggleTrack]);
- const padder = useMemo((): React.CSSProperties => {
- return {
- width: Number(INDENT) * nestedDepth,
- flexShrink: 0,
- };
- }, [nestedDepth]);
-
const isItemHidden = useMemo(() => {
return hidden[sequence.id] ?? false;
}, [hidden, sequence.id]);
@@ -233,7 +227,7 @@ export const TimelineListItem: React.FC<{
hidden={isItemHidden}
onInvoked={onToggleVisibility}
/>
- <div style={padder} />
+ <Padder depth={nestedDepth} />
{visualModeActive ? (
<TimelineExpandArrowButton
isExpanded={isExpanded}
@@ -262,8 +256,8 @@ export const TimelineListItem: React.FC<{
<TimelineExpandedSection
sequence={sequence}
originalLocation={originalLocation}
- nestedDepth={nestedDepth}
nodePath={nodePath}
+ nestedDepth={nestedDepth}
/>
) : null}
</>