🎥 Make videos programmatically with React
`@remotion/transitions`: Show `TransitionSeries.Overlay` in JSX order in Studio
Jonny Burger50e3db6377f2
diff --git a/packages/canvas/src/get-timeline-sequence-sort-key.ts b/packages/canvas/src/get-timeline-sequence-sort-key.tsindex 57e4b85080..94c9b31da1 100644--- a/packages/canvas/src/get-timeline-sequence-sort-key.ts+++ b/packages/canvas/src/get-timeline-sequence-sort-key.ts@@ -43,11 +43,7 @@ export const getTimelineSequenceSortKey = (tracks: TimelineTrackData[],sequenceRanks: Map<string, number>,): string => {- // Keep source order in the timeline even when a sibling paints later.- const rank =- track.sequence.timelineOrderWithinParent ??- sequenceRanks.get(track.sequence.id) ??- 0;+ const rank = sequenceRanks.get(track.sequence.id) ?? 0;const id = String(rank).padStart(6, '0');if (!track.sequence.parent) {return id;diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsxindex f872d9f42e..ac7361ddf7 100644--- a/packages/core/src/CompositionManager.tsx+++ b/packages/core/src/CompositionManager.tsx@@ -134,8 +134,6 @@ export type TSequence = {parent: string | null;showInTimeline: boolean;timelineOrder: number | null;- /** Source order among siblings when paint order must differ. */- timelineOrderWithinParent?: number | null;loopDisplay: LoopDisplay | undefined;getStack: () => string | null;premountDisplay: number | null;diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsxindex eb57c1c1ec..f765b03dfc 100644--- a/packages/core/src/Sequence.tsx+++ b/packages/core/src/Sequence.tsx@@ -115,10 +115,6 @@ export type SequencePropsWithoutDuration = {* @deprecated For internal use only.*/readonly _remotionInternalSingleChildComponent?: unknown;- /**- * @deprecated For internal use only.- */- readonly _remotionInternalTimelineOrderWithinParent?: number | null;/*** @deprecated For internal use only.*/@@ -173,8 +169,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<_remotionInternalStack: stack,_remotionInternalDocumentationLink: documentationLink,_remotionInternalSingleChildComponent: singleChildComponent,- _remotionInternalTimelineOrderWithinParent:- timelineOrderWithinParent = null,_remotionInternalPremountDisplay: premountDisplay,_remotionInternalPostmountDisplay: postmountDisplay,_remotionInternalIsMedia: isMedia,@@ -622,7 +616,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<premountDisplay: premountDisplay ?? null,showInTimeline,timelineOrder: null,- timelineOrderWithinParent,src: isMedia.src,getStack: () => stackRef.current,refForOutline: refForOutline ?? null,@@ -652,7 +645,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<premountDisplay: premountDisplay ?? null,showInTimeline,timelineOrder: null,- timelineOrderWithinParent,src: isMedia.data.src,getStack: () => stackRef.current,startMediaFrom: startMediaFrom ?? isMedia.data.startMediaFrom,@@ -679,7 +671,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<type: 'sequence',showInTimeline,timelineOrder: null,- timelineOrderWithinParent,loopDisplay: resolvedLoopDisplay,getStack: () => stackRef.current,premountDisplay: premountDisplay ?? null,@@ -716,7 +707,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<mediaFrameAtSequenceZero,frozenMediaFrame,singleChildComponent,- timelineOrderWithinParent,]);useSequenceRegistration({getSequence:diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsxindex 5af0f3adcd..b3bc4960d8 100644--- a/packages/transitions/src/TransitionSeries.tsx+++ b/packages/transitions/src/TransitionSeries.tsx@@ -1,5 +1,6 @@import type {FC, PropsWithChildren} from 'react';-import React, {useCallback, useMemo, useRef} from 'react';+import React, {useCallback, useMemo, useRef, useState} from 'react';+import {createPortal} from 'react-dom';import type {AbsoluteFillLayout,LayoutAndStyle,@@ -244,6 +245,11 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({const flattedChildren = useMemo(() => {return flattenChildren(children);}, [children]);+ const hasOverlay = flattedChildren.some(+ (child) => React.isValidElement(child) && child.type === SeriesOverlay,+ );+ const [overlayContainer, setOverlayContainer] =+ useState<HTMLDivElement | null>(null);const drawIfSynced = useCallback((index: number) => {const prevImage = prevImageRef?.current?.[index];@@ -317,6 +323,23 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({readonly styleWhilePremounted: React.CSSProperties | undefined;readonly styleWhilePostmounted: React.CSSProperties | undefined;};+ const renderOverlay = (info: OverlayRender) => (+ <SequenceWithoutSchema+ key={`overlay-${info.index}`}+ from={Math.round(info.overlayFrom)}+ durationInFrames={info.durationInFrames}+ name="<TS.Overlay>"+ _remotionInternalDocumentationLink="https://www.remotion.dev/docs/transitions/transitionseries"+ controls={info.controls ?? undefined}+ layout="absolute-fill"+ premountFor={info.premountFor}+ postmountFor={info.postmountFor}+ styleWhilePremounted={info.styleWhilePremounted}+ styleWhilePostmounted={info.styleWhilePostmounted}+ >+ {info.children}+ </SequenceWithoutSchema>+ );type RenderState = {readonly index: number;@@ -338,24 +361,9 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({} = state;if (i === flattedChildren.length) {- return overlayRenders.map((info) => (- <SequenceWithoutSchema- key={`overlay-${info.index}`}- from={Math.round(info.overlayFrom)}- durationInFrames={info.durationInFrames}- name="<TS.Overlay>"- _remotionInternalTimelineOrderWithinParent={info.index}- _remotionInternalDocumentationLink="https://www.remotion.dev/docs/transitions/transitionseries"- controls={info.controls ?? undefined}- layout="absolute-fill"- premountFor={info.premountFor}- postmountFor={info.postmountFor}- styleWhilePremounted={info.styleWhilePremounted}- styleWhilePostmounted={info.styleWhilePostmounted}- >- {info.children}- </SequenceWithoutSchema>- ));+ return overlayContainer === null+ ? overlayRenders.map(renderOverlay)+ : null;}const child = flattedChildren[i];@@ -477,8 +485,8 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({}}- // Store overlay info for deferred rendering and validate the other- // side once the next sequence has resolved its interactive props.+ // Store overlay info to validate the other side once the next+ // sequence has resolved its interactive props.const overlayRender: OverlayRender = {cutPoint,overlayFrom,@@ -494,10 +502,22 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({styleWhilePostmounted: overlayProps.styleWhilePostmounted,};- return renderNext({+ const rest = renderNext({overlayRenders: [...overlayRenders, overlayRender],pendingOverlayValidation: true,});+ return overlayContainer === null ? (+ rest+ ) : (+ <>+ {createPortal(+ renderOverlay(overlayRender),+ overlayContainer,+ `overlay-${i}`,+ )}+ {rest}+ </>+ );},});}@@ -538,7 +558,6 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({from={transitionFrom}durationInFrames={transitionDuration}name="<TS.Transition>"- _remotionInternalTimelineOrderWithinParent={i}_remotionInternalDocumentationLink="https://www.remotion.dev/docs/transitions/transitionseries"controls={transitionProps.controls ?? undefined}layout="none"@@ -598,7 +617,6 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({} = resolvedProps as InternalSeriesSequenceProps & {from: never};const propsForSequence = {...passedProps,- _remotionInternalTimelineOrderWithinParent: i,_remotionInternalSingleChildComponent:Internals.getSingleChildComponent(sequenceChildren),};@@ -942,10 +960,23 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({sequenceDurations: [],pendingOverlayValidation: false,});- }, [flattedChildren, fps, frame, onPrevElementImage, onNextElementImage]);+ }, [+ flattedChildren,+ fps,+ frame,+ onPrevElementImage,+ onNextElementImage,+ overlayContainer,+ ]);- // eslint-disable-next-line react/jsx-no-useless-fragment- return <>{childrenValue}</>;+ return (+ <>+ {childrenValue}+ {hasOverlay ? (+ <div ref={setOverlayContainer} style={{display: 'contents'}} />+ ) : null}+ </>+ );};/*