Skip to content

🎥 Make videos programmatically with React

improve nesting

Jonny Burger428a161c2b6e
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
new file mode 100644
index 0000000000..c43cc2f3a1
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
@@ -0,0 +1,106 @@
+import type {SequenceNodePath} from '@remotion/studio-shared';
+import React, {useMemo} from 'react';
+import type {SequenceSchema} from 'remotion';
+import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';
+import type {TimelineTreeNode} from '../../helpers/timeline-layout';
+import {
+ EXPANDED_SECTION_PADDING_LEFT,
+ EXPANDED_SECTION_PADDING_RIGHT,
+ getTreeRowHeight,
+ TREE_GROUP_ROW_HEIGHT,
+} from '../../helpers/timeline-layout';
+import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';
+import {TimelineFieldRow} from './TimelineFieldRow';
+import {INDENT} from './TimelineListItem';
+
+const groupRowBase: React.CSSProperties = {
+ height: TREE_GROUP_ROW_HEIGHT,
+ display: 'flex',
+ alignItems: 'center',
+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
+};
+
+const rowLabel: React.CSSProperties = {
+ fontSize: 12,
+ color: 'rgba(255, 255, 255, 0.8)',
+ userSelect: 'none',
+};
+
+const labelOnlyRowBase: React.CSSProperties = {
+ display: 'flex',
+ alignItems: 'center',
+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
+};
+
+export const TimelineExpandedRow: React.FC<{
+ readonly node: TimelineTreeNode;
+ readonly depth: number;
+ readonly sequenceOffsetPx: number;
+ readonly expandedTracks: Record<string, boolean>;
+ readonly toggleTrack: (id: string) => void;
+ readonly overrideId: string;
+ readonly validatedLocation: CodePosition | null;
+ readonly nodePath: SequenceNodePath | null;
+ readonly schema: SequenceSchema;
+}> = ({
+ node,
+ depth,
+ sequenceOffsetPx,
+ expandedTracks,
+ toggleTrack,
+ overrideId,
+ validatedLocation,
+ nodePath,
+ schema,
+}) => {
+ const paddingLeft =
+ EXPANDED_SECTION_PADDING_LEFT + depth * INDENT + sequenceOffsetPx;
+
+ const groupStyle = useMemo(
+ (): React.CSSProperties => ({...groupRowBase, paddingLeft}),
+ [paddingLeft],
+ );
+
+ const labelOnlyStyle = useMemo(
+ (): React.CSSProperties => ({
+ ...labelOnlyRowBase,
+ height: getTreeRowHeight(node),
+ paddingLeft,
+ }),
+ [node, paddingLeft],
+ );
+
+ if (node.kind === 'group') {
+ const isExpanded = expandedTracks[node.id] ?? false;
+ return (
+ <div style={groupStyle}>
+ <TimelineExpandArrowButton
+ isExpanded={isExpanded}
+ onClick={() => toggleTrack(node.id)}
+ label={`${node.label} section`}
+ hasExpandableContent
+ />
+ <span style={rowLabel}>{node.label}</span>
+ </div>
+ );
+ }
+
+ if (node.field) {
+ return (
+ <TimelineFieldRow
+ field={node.field}
+ overrideId={overrideId}
+ validatedLocation={validatedLocation}
+ paddingLeft={paddingLeft}
+ nodePath={nodePath}
+ schema={schema}
+ />
+ );
+ }
+
+ return (
+ <div style={labelOnlyStyle}>
+ <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 bd75c49f52..e894937a5b 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -1,26 +1,19 @@
import type {SequenceNodePath} from '@remotion/studio-shared';
-import React, {useCallback, useContext, useMemo} from 'react';
+import React, {useContext, useMemo} from 'react';
import {Internals, type TSequence} from 'remotion';
import type {
CodePosition,
OriginalPosition,
} from '../../error-overlay/react-overlay/utils/get-source-map';
import {TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';
-import type {TimelineTreeNode} from '../../helpers/timeline-layout';
import {
buildTimelineTree,
- EXPANDED_SECTION_PADDING_LEFT,
- EXPANDED_SECTION_PADDING_RIGHT,
flattenVisibleTreeNodes,
getExpandedTrackHeight,
- getTreeRowHeight,
- TREE_GROUP_ROW_HEIGHT,
- TREE_INDENT_PER_LEVEL,
} from '../../helpers/timeline-layout';
import {ExpandedTracksContext} from '../ExpandedTracksProvider';
-import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';
-import {TimelineFieldRow} from './TimelineFieldRow';
-import {SPACING} from './TimelineListItem';
+import {TimelineExpandedRow} from './TimelineExpandedRow';
+import {INDENT} from './TimelineListItem';
const expandedSectionBase: React.CSSProperties = {
color: 'white',
@@ -36,25 +29,6 @@ const separator: React.CSSProperties = {
backgroundColor: TIMELINE_TRACK_SEPARATOR,
};
-const groupRowBase: React.CSSProperties = {
- height: TREE_GROUP_ROW_HEIGHT,
- display: 'flex',
- alignItems: 'center',
- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
-};
-
-const rowLabel: React.CSSProperties = {
- fontSize: 12,
- color: 'rgba(255, 255, 255, 0.8)',
- userSelect: 'none',
-};
-
-const labelOnlyRowBase: React.CSSProperties = {
- display: 'flex',
- alignItems: 'center',
- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
-};
-
export const TimelineExpandedSection: React.FC<{
readonly sequence: TSequence;
readonly originalLocation: OriginalPosition | null;
@@ -105,7 +79,7 @@ export const TimelineExpandedSection: React.FC<{
[sequence, expandedTracks, dragOverrides, codeValues],
);
- const sequenceOffsetPx = SPACING * 3 * nestedDepth;
+ const sequenceOffsetPx = INDENT * nestedDepth;
const style = useMemo(() => {
return {
@@ -116,64 +90,6 @@ export const TimelineExpandedSection: React.FC<{
const {schema} = sequence.controls!;
- const renderRow = useCallback(
- (node: TimelineTreeNode, depth: number) => {
- const paddingLeft =
- EXPANDED_SECTION_PADDING_LEFT +
- depth * TREE_INDENT_PER_LEVEL +
- sequenceOffsetPx;
-
- if (node.kind === 'group') {
- const isExpanded = expandedTracks[node.id] ?? false;
- return (
- <div style={{...groupRowBase, paddingLeft}}>
- <TimelineExpandArrowButton
- isExpanded={isExpanded}
- onClick={() => toggleTrack(node.id)}
- label={`${node.label} section`}
- hasExpandableContent
- />
- <span style={rowLabel}>{node.label}</span>
- </div>
- );
- }
-
- if (node.field) {
- return (
- <TimelineFieldRow
- field={node.field}
- overrideId={overrideId}
- validatedLocation={validatedLocation}
- paddingLeft={paddingLeft}
- nodePath={nodePath}
- schema={schema}
- />
- );
- }
-
- return (
- <div
- style={{
- ...labelOnlyRowBase,
- height: getTreeRowHeight(node),
- paddingLeft,
- }}
- >
- <span style={rowLabel}>{node.label}</span>
- </div>
- );
- },
- [
- expandedTracks,
- nodePath,
- overrideId,
- schema,
- sequenceOffsetPx,
- toggleTrack,
- validatedLocation,
- ],
- );
-
if (flat.length === 0) {
return <div style={style}>No schema</div>;
}
@@ -184,7 +100,17 @@ export const TimelineExpandedSection: React.FC<{
return (
<React.Fragment key={node.id}>
{i > 0 ? <div style={separator} /> : null}
- {renderRow(node, depth)}
+ <TimelineExpandedRow
+ node={node}
+ depth={depth}
+ sequenceOffsetPx={sequenceOffsetPx}
+ expandedTracks={expandedTracks}
+ toggleTrack={toggleTrack}
+ overrideId={overrideId}
+ validatedLocation={validatedLocation}
+ nodePath={nodePath}
+ schema={schema}
+ />
</React.Fragment>
);
})}
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 176033bfa7..53cef1f333 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -20,12 +20,7 @@ import {TimelineStack} from './TimelineStack';
import {useResolvedStack} from './use-resolved-stack';
import {useSequencePropsSubscription} from './use-sequence-props-subscription';
-export const SPACING = 5;
-
-const space: React.CSSProperties = {
- width: SPACING,
- flexShrink: 0,
-};
+export const INDENT = 10;
export const TimelineListItem: React.FC<{
readonly sequence: TSequence;
@@ -183,7 +178,7 @@ export const TimelineListItem: React.FC<{
const padder = useMemo((): React.CSSProperties => {
return {
- width: Number(SPACING) * nestedDepth,
+ width: Number(INDENT) * nestedDepth,
flexShrink: 0,
};
}, [nestedDepth]);
@@ -223,7 +218,7 @@ export const TimelineListItem: React.FC<{
alignItems: 'center',
wordBreak: 'break-all',
textAlign: 'left',
- paddingLeft: SPACING,
+ paddingLeft: 5,
};
}, []);
@@ -239,7 +234,6 @@ export const TimelineListItem: React.FC<{
onInvoked={onToggleVisibility}
/>
<div style={padder} />
- {sequence.parent && nestedDepth > 0 ? <div style={space} /> : null}
{visualModeActive ? (
<TimelineExpandArrowButton
isExpanded={isExpanded}
diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.ts
index 896e4a561d..d773274d4c 100644
--- a/packages/studio/src/helpers/timeline-layout.ts
+++ b/packages/studio/src/helpers/timeline-layout.ts
@@ -21,7 +21,6 @@ export const TIMELINE_ITEM_BORDER_BOTTOM = 1;
export const TIMELINE_TRACK_EXPANDED_HEIGHT = 100;
export const TREE_GROUP_ROW_HEIGHT = 22;
-export const TREE_INDENT_PER_LEVEL = 16;
export const EXPANDED_SECTION_PADDING_LEFT = 28;
export const EXPANDED_SECTION_PADDING_RIGHT = 10;