Skip to content

🎥 Make videos programmatically with React

add it to the core

Jonny Burger48b3068a0835
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index 15356ba8d2..bba7e7321c 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -46,6 +46,7 @@ export type SequencePropsWithoutDuration = {
* @deprecated For internal use only.
*/
stack?: string;
+ premountFor?: number;
} & LayoutAndStyle;
export type SequenceProps = {
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index dcf676e449..583c234e37 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -120,6 +120,7 @@ export {
RandomSeed,
} from './no-react';
export {prefetch, PrefetchOnProgress} from './prefetch.js';
+export {PremountedSequence} from './premounted-sequence';
export {registerRoot} from './register-root.js';
export {
LayoutAndStyle,
diff --git a/packages/core/src/premounted-sequence.tsx b/packages/core/src/premounted-sequence.tsx
new file mode 100644
index 0000000000..55778f2800
--- /dev/null
+++ b/packages/core/src/premounted-sequence.tsx
@@ -0,0 +1,40 @@
+import React, {useMemo} from 'react';
+import {Freeze} from './freeze';
+import type {SequenceProps} from './Sequence';
+import {Sequence} from './Sequence';
+import {useCurrentFrame} from './use-current-frame';
+
+export const PremountedSequence: React.FC<
+ {
+ children: React.ReactNode;
+ premountFor: number;
+ } & SequenceProps
+> = ({premountFor, ...props}) => {
+ const frame = useCurrentFrame();
+
+ if (props.layout === 'none') {
+ throw new Error('`<Premount>` does not support layout="none"');
+ }
+
+ const {style: passedStyle, from = 0, ...otherProps} = props;
+ const active = frame < premountFor + from;
+
+ const style = useMemo(() => {
+ return {
+ ...passedStyle,
+ opacity: active ? 0 : 1,
+ pointerEvents: active ? 'none' : passedStyle?.pointerEvents ?? 'auto',
+ };
+ }, [active, passedStyle]);
+
+ return (
+ <Freeze frame={frame >= from ? from : -1} active={active}>
+ <Sequence
+ name={`<Premount premountFor={${premountFor}}>`}
+ from={from + (active ? 0 : premountFor)}
+ style={style}
+ {...otherProps}
+ />
+ </Freeze>
+ );
+};
diff --git a/packages/example/src/Premount/index.tsx b/packages/example/src/Premount/index.tsx
index 2198fcf713..6f6f645b22 100644
--- a/packages/example/src/Premount/index.tsx
+++ b/packages/example/src/Premount/index.tsx
@@ -1,48 +1,5 @@
-import React, {useMemo} from 'react';
-import {
- AbsoluteFill,
- Freeze,
- Sequence,
- SequenceProps,
- staticFile,
- useCurrentFrame,
- Video,
-} from 'remotion';
-
-const Premount: React.FC<
- {
- children: React.ReactNode;
- premountFor: number;
- } & SequenceProps
-> = ({premountFor, ...props}) => {
- const frame = useCurrentFrame();
-
- if (props.layout === 'none') {
- throw new Error('`<Premount>` does not support layout="none"');
- }
-
- const {style: passedStyle, from = 0, ...otherProps} = props;
- const active = frame < premountFor + from;
-
- const style = useMemo(() => {
- return {
- ...passedStyle,
- opacity: active ? 0 : 1,
- pointerEvents: active ? 'none' : passedStyle?.pointerEvents ?? 'auto',
- };
- }, [active, passedStyle]);
-
- return (
- <Freeze frame={frame >= from ? from : -1} active={active}>
- <Sequence
- name={`<Premount premountFor={${premountFor}}>`}
- from={from + (active ? 0 : premountFor)}
- style={style}
- {...otherProps}
- />
- </Freeze>
- );
-};
+import React from 'react';
+import {AbsoluteFill, PremountedSequence, staticFile, Video} from 'remotion';
const ShouldNotUnmount: React.FC = () => {
return <Video src={staticFile('framer.webm')} />;
@@ -51,9 +8,12 @@ const ShouldNotUnmount: React.FC = () => {
export const PremountedExample: React.FC = () => {
return (
<AbsoluteFill>
- <Premount premountFor={10} from={30} durationInFrames={200}>
+ <PremountedSequence premountFor={10} from={30} durationInFrames={200}>
+ <ShouldNotUnmount />
+ </PremountedSequence>
+ <PremountedSequence premountFor={10} from={30} durationInFrames={200}>
<ShouldNotUnmount />
- </Premount>
+ </PremountedSequence>
</AbsoluteFill>
);
};