Skip to content

🎥 Make videos programmatically with React

width height

Jonny Burger6aaf702a278b
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index d2e8bff7bd..2b17f35933 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -198,15 +198,13 @@ const SequenceRefForwardingFunction: React.ForwardRefRenderFunction<
const styleIfThere = other.layout === 'none' ? undefined : other.style;
const defaultStyle: React.CSSProperties = useMemo(() => {
- const widthValue = width ?? parentSequence?.width;
- const heightValue = height ?? parentSequence?.height;
return {
flexDirection: undefined,
+ ...(width ? {width} : {}),
+ ...(height ? {height} : {}),
...(styleIfThere ?? {}),
- ...(widthValue ? {width: widthValue} : {}),
- ...(heightValue ? {height: heightValue} : {}),
};
- }, [height, parentSequence, styleIfThere, width]);
+ }, [height, styleIfThere, width]);
if (ref !== null && layout === 'none') {
throw new TypeError(
diff --git a/packages/core/src/use-unsafe-video-config.ts b/packages/core/src/use-unsafe-video-config.ts
index cfb9a1fabc..9076120f99 100644
--- a/packages/core/src/use-unsafe-video-config.ts
+++ b/packages/core/src/use-unsafe-video-config.ts
@@ -5,6 +5,8 @@ import type {VideoConfig} from './video-config.js';
export const useUnsafeVideoConfig = (): VideoConfig | null => {
const context = useContext(SequenceContext);
+ const ctxWidth = context?.width ?? null;
+ const ctxHeight = context?.height ?? null;
const ctxDuration = context?.durationInFrames ?? null;
const video = useVideo();
@@ -26,13 +28,13 @@ export const useUnsafeVideoConfig = (): VideoConfig | null => {
return {
id,
- width,
- height,
+ width: ctxWidth ?? width,
+ height: ctxHeight ?? height,
fps,
durationInFrames: ctxDuration ?? durationInFrames,
defaultProps,
props,
defaultCodec,
};
- }, [ctxDuration, video]);
+ }, [ctxDuration, ctxHeight, ctxWidth, video]);
};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index cb451c40ec..1b91a59cf9 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -43,6 +43,7 @@ import {
schemaTestSchema,
} from './SchemaTest';
import {Scripts} from './Scripts';
+import {WidthHeightSequences} from './Sequence/WidthHeightSequences';
import CircleTest from './Shapes/CircleTest';
import EllipseTest from './Shapes/EllipseTest';
import RectTest from './Shapes/RectTest';
@@ -1070,6 +1071,14 @@ export const Index: React.FC = () => {
fps={30}
defaultProps={{}}
/>
+ <Composition
+ id="WidthHeight"
+ component={WidthHeightSequences}
+ fps={30}
+ height={1080}
+ width={1080}
+ durationInFrames={120}
+ />
</>
);
};
diff --git a/packages/example/src/Sequence/WidthHeightSequences.tsx b/packages/example/src/Sequence/WidthHeightSequences.tsx
new file mode 100644
index 0000000000..7e26bd42b2
--- /dev/null
+++ b/packages/example/src/Sequence/WidthHeightSequences.tsx
@@ -0,0 +1,32 @@
+import React from 'react';
+import {AbsoluteFill, Sequence, useVideoConfig} from 'remotion';
+
+const Inner: React.FC = () => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <Sequence width={width / 2} height={height / 2}>
+ <AbsoluteFill
+ style={{
+ backgroundColor: 'blue',
+ }}
+ />
+ </Sequence>
+ );
+};
+
+export const WidthHeightSequences: React.FC = () => {
+ const {height, width} = useVideoConfig();
+
+ return (
+ <Sequence width={width / 2} height={height / 2}>
+ <AbsoluteFill
+ style={{
+ backgroundColor: 'red',
+ }}
+ >
+ <Inner />
+ </AbsoluteFill>
+ </Sequence>
+ );
+};