🎥 Make videos programmatically with React
work premount into sequence
Jonny Burgerfd52c8471ac1
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsxindex 15356ba8d2..46c2d91a7f 100644--- a/packages/core/src/Sequence.tsx+++ b/packages/core/src/Sequence.tsx@@ -1,3 +1,4 @@+/* eslint-disable @typescript-eslint/no-use-before-define */import React, {forwardRef,useContext,@@ -21,9 +22,13 @@ import {} from './timeline-position-state.js';import {useVideoConfig} from './use-video-config.js';+import {Freeze} from './freeze.js';+import {useCurrentFrame} from './use-current-frame';+export type LayoutAndStyle =| {layout?: 'absolute-fill';+ premountFor?: number;style?: React.CSSProperties;className?: string;}@@ -52,7 +57,7 @@ export type SequenceProps = {durationInFrames?: number;} & SequencePropsWithoutDuration;-const SequenceRefForwardingFunction: React.ForwardRefRenderFunction<+const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<HTMLDivElement,SequenceProps> = (@@ -239,6 +244,62 @@ const SequenceRefForwardingFunction: React.ForwardRefRenderFunction<);};+const RegularSequence = forwardRef(RegularSequenceRefForwardingFunction);++const PremountedSequenceRefForwardingFunction: React.ForwardRefRenderFunction<+ HTMLDivElement,+ SequenceProps+> = (props, ref) => {+ const frame = useCurrentFrame();++ if (props.layout === 'none') {+ throw new Error(+ '`<Sequence>` with `premountFor` prop does not support layout="none"',+ );+ }++ const {+ style: passedStyle,+ from = 0,+ premountFor = 0,+ name,+ ...otherProps+ } = props;+ const active = frame < from && !getRemotionEnvironment().isRendering;++ const style = useMemo(() => {+ return {+ ...passedStyle,+ opacity: active ? 0 : 1,+ pointerEvents: active ? 'none' : passedStyle?.pointerEvents ?? 'auto',+ };+ }, [active, passedStyle]);++ return (+ <Freeze frame={from} active={active}>+ <Sequence+ ref={ref}+ name={name ?? `<Premount premountFor={${premountFor}}>`}+ from={from + (active ? -premountFor : 0)}+ style={style}+ {...otherProps}+ />+ </Freeze>+ );+};++const PremountedSequence = forwardRef(PremountedSequenceRefForwardingFunction);+const SequenceRefForwardingFunction: React.ForwardRefRenderFunction<+ HTMLDivElement,+ SequenceProps+> = (props, ref) => {+ if (props.layout !== 'none' && props.premountFor) {+ return <PremountedSequence {...props} ref={ref} />;+ }++ return <RegularSequence {...props} ref={ref} />;+};+/*** @description A component that time-shifts its children and wraps them in an absolutely positioned <div>.* @see [Documentation](https://www.remotion.dev/docs/sequence)diff --git a/packages/core/src/premounted-sequence.tsx b/packages/core/src/premounted-sequence.tsxdeleted file mode 100644index e066fb65de..0000000000--- a/packages/core/src/premounted-sequence.tsx+++ /dev/null@@ -1,50 +0,0 @@-import React, {forwardRef, useMemo} from 'react';-import {Freeze} from './freeze';-import {getRemotionEnvironment} from './get-remotion-environment';-import type {SequenceProps} from './Sequence';-import {Sequence} from './Sequence';-import {useCurrentFrame} from './use-current-frame';--export type PremountedSequenceProps = SequenceProps & {- premountFor: number;-};--const PremountedSequenceRefForwardingFunction: React.ForwardRefRenderFunction<- HTMLDivElement,- {- premountFor: number;- } & SequenceProps-> = ({premountFor, ...props}, ref) => {- 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 < from && !getRemotionEnvironment().isRendering;-- const style = useMemo(() => {- return {- ...passedStyle,- opacity: active ? 0 : 1,- pointerEvents: active ? 'none' : passedStyle?.pointerEvents ?? 'auto',- };- }, [active, passedStyle]);-- return (- <Freeze frame={from} active={active}>- <Sequence- ref={ref}- name={`<Premount premountFor={${premountFor}}>`}- from={from + (active ? -premountFor : 0)}- style={style}- {...otherProps}- />- </Freeze>- );-};--export const PremountedSequence = forwardRef(- PremountedSequenceRefForwardingFunction,-);