Skip to content

🎥 Make videos programmatically with React

allow <Sequence> to have a style

Jonny Burger619f2acd4df0
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index 4ef1f3b8d4..f5a69fbc17 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -5,6 +5,7 @@ import React, {
useMemo,
useState,
} from 'react';
+import {AbsoluteFill} from './AbsoluteFill';
import {CompositionManager} from './CompositionManager';
import {getTimelineClipName} from './get-timeline-clip-name';
import {useNonce} from './nonce';
@@ -22,25 +23,34 @@ export type SequenceContextType = {
export const SequenceContext = createContext<SequenceContextType | null>(null);
+type LayoutAndStyle =
+ | {
+ layout: 'none';
+ }
+ | {
+ layout?: 'absolute-fill';
+ style?: React.CSSProperties;
+ };
+
export type SequenceProps = {
children: React.ReactNode;
from: number;
durationInFrames?: number;
name?: string;
- layout?: 'absolute-fill' | 'none';
showInTimeline?: boolean;
showLoopTimesInTimeline?: number;
-};
+} & LayoutAndStyle;
export const Sequence: React.FC<SequenceProps> = ({
from,
durationInFrames = Infinity,
children,
name,
- layout = 'absolute-fill',
showInTimeline = true,
showLoopTimesInTimeline,
+ ...other
}) => {
+ const {layout = 'absolute-fill'} = other;
const [id] = useState(() => String(Math.random()));
const parentSequence = useContext(SequenceContext);
const {rootId} = useContext(TimelineContext);
@@ -169,23 +179,19 @@ export const Sequence: React.FC<SequenceProps> = ({
? null
: children;
+ const styleIfThere = other.layout === 'none' ? undefined : other.style;
+
+ const defaultStyle: React.CSSProperties = useMemo(() => {
+ return {
+ flexDirection: undefined,
+ ...(styleIfThere ?? {}),
+ };
+ }, [styleIfThere]);
+
return (
<SequenceContext.Provider value={contextValue}>
{content === null ? null : layout === 'absolute-fill' ? (
- <div
- style={{
- position: 'absolute',
- display: 'flex',
- width: '100%',
- height: '100%',
- top: 0,
- bottom: 0,
- left: 0,
- right: 0,
- }}
- >
- {content}
- </div>
+ <AbsoluteFill style={defaultStyle}>{content}</AbsoluteFill>
) : (
content
)}