Skip to content

🎥 Make videos programmatically with React

Add premounting to timed visual components

Jonny Burgerc09e6b6ee962
diff --git a/packages/core/src/AbsoluteFill.tsx b/packages/core/src/AbsoluteFill.tsx
index 3a4f0a785c..08080238a8 100644
--- a/packages/core/src/AbsoluteFill.tsx
+++ b/packages/core/src/AbsoluteFill.tsx
@@ -5,10 +5,14 @@ import {
} from './AbsoluteFillElement.js';
import type {SequenceControls} from './CompositionManager.js';
import {addSequenceStackTraces} from './enable-sequence-stack-traces.js';
-import type {InteractiveBaseProps} from './Interactive.js';
+import type {
+ InteractiveBaseProps,
+ InteractivePremountProps,
+} from './Interactive.js';
import {
backgroundSchema,
baseSchema,
+ premountSchema,
borderRadiusSchema,
borderSchema,
textContentSchema,
@@ -16,7 +20,7 @@ import {
transformSchema,
type InteractivitySchema,
} from './interactivity-schema.js';
-import {Sequence} from './Sequence.js';
+import {PremountedSequence} from './PremountedSequence.js';
import {useUnsafeVideoConfig} from './use-unsafe-video-config.js';
import {withInteractivitySchema} from './with-interactivity-schema.js';
@@ -24,7 +28,8 @@ export type AbsoluteFillProps = Omit<
AbsoluteFillElementProps,
keyof InteractiveBaseProps
> &
- InteractiveBaseProps & {
+ InteractiveBaseProps &
+ InteractivePremountProps & {
/**
* @deprecated For internal use only
*/
@@ -33,6 +38,7 @@ export type AbsoluteFillProps = Omit<
export const absoluteFillSchema = {
...baseSchema,
+ ...premountSchema,
...transformSchema,
...backgroundSchema,
...borderSchema,
@@ -57,6 +63,10 @@ const AbsoluteFillInner: React.FC<
> = ({
ref,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -88,8 +98,13 @@ const AbsoluteFillInner: React.FC<
}
return (
- <Sequence
- layout="none"
+ <PremountedSequence
+ hideWhilePremounted="opacity"
+ style={divProps.style ?? null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -103,10 +118,16 @@ const AbsoluteFillInner: React.FC<
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/absolute-fill"
outlineRef={refForOutline}
>
- <AbsoluteFillElement ref={callbackRef} {...divProps}>
- {children}
- </AbsoluteFillElement>
- </Sequence>
+ {(premountingStyle) => (
+ <AbsoluteFillElement
+ ref={callbackRef}
+ {...divProps}
+ style={premountingStyle ?? undefined}
+ >
+ {children}
+ </AbsoluteFillElement>
+ )}
+ </PremountedSequence>
);
};
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsx
index 85ac6d06c1..8ad5269534 100644
--- a/packages/core/src/HtmlInCanvas.tsx
+++ b/packages/core/src/HtmlInCanvas.tsx
@@ -23,14 +23,15 @@ import type {
import {
backgroundSchema,
baseSchema,
+ premountSchema,
borderRadiusSchema,
borderSchema,
cropSchema,
transformSchema,
type InteractivitySchema,
} from './interactivity-schema.js';
+import {PremountedSequence} from './PremountedSequence.js';
import type {AbsoluteFillLayout} from './Sequence.js';
-import {Sequence} from './Sequence.js';
import {useCropStyle} from './use-crop-style.js';
import {useDelayRender} from './use-delay-render.js';
import {useRemotionEnvironment} from './use-remotion-environment.js';
@@ -343,14 +344,7 @@ const defaultOnPaint = ({
/* eslint-disable react/require-default-props -- optional fields mirror `<Sequence>` / canvas hooks API */
export type HtmlInCanvasProps = Omit<InteractiveBaseProps, 'children'> &
InteractiveCropProps &
- Omit<
- AbsoluteFillLayout,
- | 'layout'
- | 'styleWhilePostmounted'
- | 'postmountFor'
- | 'premountFor'
- | 'styleWhilePremounted'
- > & {
+ Omit<AbsoluteFillLayout, 'layout'> & {
readonly durationInFrames?: number;
readonly width: number;
readonly height: number;
@@ -746,6 +740,10 @@ const HtmlInCanvasInner = forwardRef<
cropTop,
cropBottom,
durationInFrames,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
name,
...sequenceProps
},
@@ -774,30 +772,37 @@ const HtmlInCanvasInner = forwardRef<
});
return (
- <Sequence
+ <PremountedSequence
durationInFrames={durationInFrames}
name={name ?? '<HtmlInCanvas>'}
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/remotion/html-in-canvas"
controls={controls}
_remotionInternalEffects={memoizedEffectDefinitions}
outlineRef={actualRef}
- layout="none"
+ hideWhilePremounted="opacity"
+ style={croppedStyle}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
{...sequenceProps}
>
- <HtmlInCanvasContent
- ref={setCanvasRef}
- width={width}
- height={height}
- effects={effects}
- onPaint={onPaint}
- onInit={onInit}
- pixelDensity={pixelDensity}
- controls={controls}
- style={croppedStyle ?? undefined}
- >
- {children}
- </HtmlInCanvasContent>
- </Sequence>
+ {(premountingStyle) => (
+ <HtmlInCanvasContent
+ ref={setCanvasRef}
+ width={width}
+ height={height}
+ effects={effects}
+ onPaint={onPaint}
+ onInit={onInit}
+ pixelDensity={pixelDensity}
+ controls={controls}
+ style={premountingStyle ?? undefined}
+ >
+ {children}
+ </HtmlInCanvasContent>
+ )}
+ </PremountedSequence>
);
},
);
@@ -806,6 +811,7 @@ HtmlInCanvasInner.displayName = 'HtmlInCanvas';
export const htmlInCanvasSchema = {
...baseSchema,
+ ...premountSchema,
pixelDensity: {
type: 'number',
min: 1,
diff --git a/packages/core/src/Interactive.tsx b/packages/core/src/Interactive.tsx
index 3b622806bf..75bbd4c8c7 100644
--- a/packages/core/src/Interactive.tsx
+++ b/packages/core/src/Interactive.tsx
@@ -20,8 +20,8 @@ import {
transformSchema,
type InteractivitySchema,
} from './interactivity-schema.js';
+import {PremountedSequence} from './PremountedSequence.js';
import type {AbsoluteFillLayout, SequenceProps} from './Sequence.js';
-import {Sequence} from './Sequence.js';
import {useCropStyle} from './use-crop-style.js';
import {
withInteractivitySchema,
@@ -103,7 +103,9 @@ export type InteractivePremountProps = Pick<
| 'styleWhilePostmounted'
>;
-type InteractiveManagedProps = InteractiveBaseProps & InteractiveCropProps;
+type InteractiveManagedProps = InteractiveBaseProps &
+ InteractiveCropProps &
+ InteractivePremountProps;
type InteractiveElementProps<Tag extends InteractiveTag> = Omit<
React.ComponentPropsWithoutRef<Tag>,
@@ -147,6 +149,7 @@ const makeRemotionComponentIdentity = ({
const interactiveElementSchema = {
...baseSchema,
+ ...premountSchema,
...transformSchema,
...cropSchema,
} as const satisfies InteractivitySchema;
@@ -227,6 +230,10 @@ const makeInteractiveElement = <Tag extends InteractiveTag>(
const {
durationInFrames,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -261,8 +268,13 @@ const makeInteractiveElement = <Tag extends InteractiveTag>(
);
return (
- <Sequence
- layout="none"
+ <PremountedSequence
+ hideWhilePremounted="opacity"
+ style={croppedStyle}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -275,12 +287,14 @@ const makeInteractiveElement = <Tag extends InteractiveTag>(
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/interactive"
outlineRef={refForOutline}
>
- {React.createElement(tag, {
- ...props,
- style: croppedStyle ?? undefined,
- ref: callbackRef,
- })}
- </Sequence>
+ {(premountingStyle) =>
+ React.createElement(tag, {
+ ...props,
+ style: premountingStyle ?? undefined,
+ ref: callbackRef,
+ })
+ }
+ </PremountedSequence>
);
});
diff --git a/packages/core/src/PremountedSequence.tsx b/packages/core/src/PremountedSequence.tsx
new file mode 100644
index 0000000000..52a723b088
--- /dev/null
+++ b/packages/core/src/PremountedSequence.tsx
@@ -0,0 +1,61 @@
+import type React from 'react';
+import {Freeze} from './freeze.js';
+import type {InteractivePremountProps} from './Interactive.js';
+import {Sequence, type SequenceProps} from './Sequence.js';
+import {usePremounting} from './use-premounting.js';
+
+// Components that own their DOM element cannot use Sequence's layout wrapper.
+// Keep the timing and registration shared, and let the caller hide its element.
+export const PremountedSequence = ({
+ from = 0,
+ durationInFrames = Infinity,
+ premountFor,
+ postmountFor,
+ style,
+ styleWhilePremounted,
+ styleWhilePostmounted,
+ hideWhilePremounted,
+ children,
+ ...props
+}: Omit<SequenceProps, 'children' | 'layout' | 'style'> &
+ InteractivePremountProps & {
+ readonly style: React.CSSProperties | null;
+ readonly hideWhilePremounted: 'opacity' | 'display-none';
+ readonly children: (style: React.CSSProperties | null) => React.ReactNode;
+ }) => {
+ const {
+ effectivePremountFor,
+ effectivePostmountFor,
+ freezeFrame,
+ isPremountingOrPostmounting,
+ premountingActive,
+ postmountingActive,
+ premountingStyle,
+ } = usePremounting({
+ from,
+ durationInFrames,
+ premountFor: premountFor ?? null,
+ postmountFor: postmountFor ?? null,
+ style,
+ styleWhilePremounted: styleWhilePremounted ?? null,
+ styleWhilePostmounted: styleWhilePostmounted ?? null,
+ hideWhilePremounted,
+ });
+
+ return (
+ <Freeze frame={freezeFrame} active={isPremountingOrPostmounting}>
+ <Sequence
+ {...props}
+ layout="none"
+ from={from}
+ durationInFrames={durationInFrames}
+ _remotionInternalPremountDisplay={effectivePremountFor || null}
+ _remotionInternalPostmountDisplay={effectivePostmountFor || null}
+ _remotionInternalIsPremounting={premountingActive}
+ _remotionInternalIsPostmounting={postmountingActive}
+ >
+ {children(premountingStyle)}
+ </Sequence>
+ </Freeze>
+ );
+};
diff --git a/packages/core/src/effects/Solid.tsx b/packages/core/src/effects/Solid.tsx
index d286e3e3cf..3d2e0f191d 100644
--- a/packages/core/src/effects/Solid.tsx
+++ b/packages/core/src/effects/Solid.tsx
@@ -11,18 +11,20 @@ import type {SequenceControls} from '../CompositionManager.js';
import {addSequenceStackTraces} from '../enable-sequence-stack-traces.js';
import type {
InteractiveBaseProps,
+ InteractivePremountProps,
InteractiveCropProps,
} from '../Interactive.js';
import {
backgroundSchema,
baseSchema,
+ premountSchema,
borderRadiusSchema,
borderSchema,
cropSchema,
transformSchema,
type InteractivitySchema,
} from '../interactivity-schema.js';
-import {Sequence} from '../Sequence.js';
+import {PremountedSequence} from '../PremountedSequence.js';
import {useCropStyle} from '../use-crop-style.js';
import {useDelayRender} from '../use-delay-render.js';
import {withInteractivitySchema} from '../with-interactivity-schema.js';
@@ -75,6 +77,7 @@ export type SolidProps = MandatoryProps &
export const solidSchema = {
...baseSchema,
+ ...premountSchema,
color: {
type: 'color',
default: 'transparent',
@@ -254,7 +257,8 @@ const SolidOuter = forwardRef<
HTMLCanvasElement,
SolidProps & {
readonly controls: SequenceControls | undefined;
- } & InteractiveBaseProps
+ } & InteractiveBaseProps &
+ InteractivePremountProps
>(
(
{
@@ -268,6 +272,10 @@ const SolidOuter = forwardRef<
style,
name,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -300,8 +308,13 @@ const SolidOuter = forwardRef<
});
return (
- <Sequence
- layout="none"
+ <PremountedSequence
+ hideWhilePremounted="opacity"
+ style={croppedStyle}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -316,18 +329,20 @@ const SolidOuter = forwardRef<
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/solid"
{...props}
>
- <SolidInner
- reference={actualRef}
- overrideId={controls?.overrideId ?? null}
- color={color}
- height={height}
- width={width}
- className={className}
- style={croppedStyle ?? undefined}
- effects={effects}
- pixelDensity={pixelDensity}
- />
- </Sequence>
+ {(premountingStyle) => (
+ <SolidInner
+ reference={actualRef}
+ overrideId={controls?.overrideId ?? null}
+ color={color}
+ height={height}
+ width={width}
+ className={className}
+ style={premountingStyle ?? undefined}
+ effects={effects}
+ pixelDensity={pixelDensity}
+ />
+ )}
+ </PremountedSequence>
);
},
);
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 1e9a23555b..511fb20398 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -130,6 +130,7 @@ import {portalNode, setPortalNodeCurrentScale} from './portal-node.js';
import {PrefetchProvider} from './prefetch-state.js';
import {usePreload} from './prefetch.js';
import {PremountContext} from './PremountContext.js';
+import {PremountedSequence} from './PremountedSequence.js';
import {getRoot, waitForRoot} from './register-root.js';
import type {RemotionEnvironment} from './remotion-environment-context.js';
import {RemotionEnvironmentContext} from './remotion-environment-context.js';
@@ -359,6 +360,7 @@ export const Internals = {
SequenceContext,
PremountContext,
usePremounting,
+ PremountedSequence,
useRemotionContexts,
RemotionContextProvider,
CSSUtils,
diff --git a/packages/core/src/loop/index.tsx b/packages/core/src/loop/index.tsx
index f170c3de49..07af9d82d9 100644
--- a/packages/core/src/loop/index.tsx
+++ b/packages/core/src/loop/index.tsx
@@ -89,7 +89,6 @@ export const Loop: React.FC<LoopProps> & {
const maxTimes = Math.ceil(compDuration / durationInFrames);
const actualTimes = Math.min(maxTimes, times);
- const style = props.layout === 'none' ? undefined : props.style;
const maxFrame = durationInFrames * (actualTimes - 1);
const loopsElapsed = currentFrame / durationInFrames;
const nearestIteration = Math.round(loopsElapsed);
@@ -98,9 +97,15 @@ export const Loop: React.FC<LoopProps> & {
const isAtBoundary =
Math.abs(loopsElapsed - nearestIteration) <=
Number.EPSILON * Math.max(1, Math.abs(loopsElapsed)) * 4;
- const iteration = isAtBoundary ? nearestIteration : Math.floor(loopsElapsed);
+ const iteration = Math.max(
+ 0,
+ Math.min(
+ actualTimes - 1,
+ isAtBoundary ? nearestIteration : Math.floor(loopsElapsed),
+ ),
+ );
const start = isAtBoundary ? currentFrame : iteration * durationInFrames;
- const from = Math.min(start, maxFrame);
+ const from = Math.max(0, Math.min(start, maxFrame));
const loopDisplay: LoopDisplay = useMemo(() => {
return {
@@ -126,6 +131,10 @@ export const Loop: React.FC<LoopProps> & {
[loopStartFrame, firstVisibleFrame, endFrame, parentPlaybackRate],
);
+ if (actualTimes === 0) {
+ return null;
+ }
+
return (
<LoopTimelineContext.Provider value={timelineContext}>
<LoopContext.Provider value={loopContext}>
@@ -135,8 +144,7 @@ export const Loop: React.FC<LoopProps> & {
name={name ?? '<Loop>'}
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/loop"
_remotionInternalLoopDisplay={loopDisplay}
- layout={props.layout}
- style={style}
+ {...props}
showInTimeline={showInTimeline}
playbackRate={playbackRate}
>
diff --git a/packages/lottie/src/Lottie.tsx b/packages/lottie/src/Lottie.tsx
index a114d620a9..747b82e687 100644
--- a/packages/lottie/src/Lottie.tsx
+++ b/packages/lottie/src/Lottie.tsx
@@ -1,7 +1,7 @@
import type {AnimationItem} from 'lottie-web';
import lottie from 'lottie-web';
import {useEffect, useRef, useState} from 'react';
-import {useCurrentFrame, useDelayRender} from 'remotion';
+import {Internals, useCurrentFrame, useDelayRender} from 'remotion';
import type {LottieProps} from './types';
import {getLottieFrame} from './utils';
import {validateLoop} from './validate-loop';
@@ -11,7 +11,7 @@ import {validatePlaybackRate} from './validate-playbackrate';
* @description Part of the @remotion/lottie package.
* @see [Documentation](https://www.remotion.dev/docs/lottie/lottie)
*/
-export const Lottie = ({
+const LottieContent = ({
animationData,
className,
direction,
@@ -171,3 +171,41 @@ export const Lottie = ({
return <div ref={containerRef} className={className} style={style} />;
};
+
+export const Lottie = ({
+ from,
+ durationInFrames,
+ trimBefore,
+ freeze,
+ hidden,
+ name,
+ showInTimeline,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
+ style,
+ ...props
+}: LottieProps) => {
+ return (
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={style ?? null}
+ from={from}
+ durationInFrames={durationInFrames}
+ trimBefore={trimBefore}
+ freeze={freeze}
+ hidden={hidden}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
+ name={name ?? '<Lottie>'}
+ showInTimeline={showInTimeline ?? false}
+ >
+ {(premountingStyle) => (
+ <LottieContent {...props} style={premountingStyle ?? undefined} />
+ )}
+ </Internals.PremountedSequence>
+ );
+};
diff --git a/packages/lottie/src/types.ts b/packages/lottie/src/types.ts
index 21ee873b48..86d7e400dc 100644
--- a/packages/lottie/src/types.ts
+++ b/packages/lottie/src/types.ts
@@ -1,5 +1,6 @@
import type {AnimationItem} from 'lottie-web';
import type {CSSProperties} from 'react';
+import type {InteractiveBaseProps, InteractivePremountProps} from 'remotion';
export type LottieAnimationData = {
fr: number;
@@ -19,48 +20,49 @@ export type AspectRatioConstraint =
| 'xMinYMax'
| 'xMidYMax';
-export type LottieProps = {
- /**
- * JSON object with the animation data.
- * */
- animationData: LottieAnimationData;
- /**
- * CSS classes to apply on the container of the animation.
- */
- className?: string;
- /**
- * The direction of the animation. Defaults to forward.
- */
- direction?: 'forward' | 'backward';
- /**
- * If the animation should loop after its end.
- */
- loop?: boolean;
- /**
- * The speed of the animation. Defaults to 1.
- */
- playbackRate?: number;
- /**
- * CSS properties to apply to the container of the animation.
- */
- style?: CSSProperties;
- /**
- * The render engine of the Lotti files.
- */
- renderer?: 'svg' | 'canvas' | 'html';
- /**
- * for svg and canvas renderer it simulates the behavior of the preserveAspectRatio property on svgs.
- * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
- */
+export type LottieProps = Omit<InteractiveBaseProps, 'playbackRate'> &
+ InteractivePremountProps & {
+ /**
+ * JSON object with the animation data.
+ * */
+ animationData: LottieAnimationData;
+ /**
+ * CSS classes to apply on the container of the animation.
+ */
+ className?: string;
+ /**
+ * The direction of the animation. Defaults to forward.
+ */
+ direction?: 'forward' | 'backward';
+ /**
+ * If the animation should loop after its end.
+ */
+ loop?: boolean;
+ /**
+ * The speed of the animation. Defaults to 1.
+ */
+ playbackRate?: number;
+ /**
+ * CSS properties to apply to the container of the animation.
+ */
+ style?: CSSProperties;
+ /**
+ * The render engine of the Lotti files.
+ */
+ renderer?: 'svg' | 'canvas' | 'html';
+ /**
+ * for svg and canvas renderer it simulates the behavior of the preserveAspectRatio property on svgs.
+ * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
+ */
- preserveAspectRatio?:
- | AspectRatioConstraint
- | `${AspectRatioConstraint} ${'slice' | 'meet'}`;
+ preserveAspectRatio?:
+ | AspectRatioConstraint
+ | `${AspectRatioConstraint} ${'slice' | 'meet'}`;
- assetsPath?: string;
+ assetsPath?: string;
- /**
- * Callback that gets invoked when new animation data has been initialized
- */
- onAnimationLoaded?: (animation: AnimationItem) => void;
-};
+ /**
+ * Callback that gets invoked when new animation data has been initialized
+ */
+ onAnimationLoaded?: (animation: AnimationItem) => void;
+ };
diff --git a/packages/mac-cursors/src/MacOSCursor.tsx b/packages/mac-cursors/src/MacOSCursor.tsx
index c8f2d17cb0..f2143c5995 100644
--- a/packages/mac-cursors/src/MacOSCursor.tsx
+++ b/packages/mac-cursors/src/MacOSCursor.tsx
@@ -2,21 +2,24 @@ import type {CSSProperties} from 'react';
import React from 'react';
import type {
InteractiveBaseProps,
+ InteractivePremountProps,
InteractivitySchema,
SequenceControls,
} from 'remotion';
-import {Interactive, Sequence} from 'remotion';
+import {Interactive, Internals} from 'remotion';
import {macOSCursorNames, resolveCursor} from './resolve-cursor';
-export type MacOSCursorProps = InteractiveBaseProps & {
- readonly cursor?: string;
- readonly customCursor?: string;
- readonly className?: string;
- readonly style?: CSSProperties;
-};
+export type MacOSCursorProps = InteractiveBaseProps &
+ InteractivePremountProps & {
+ readonly cursor?: string;
+ readonly customCursor?: string;
+ readonly className?: string;
+ readonly style?: CSSProperties;
+ };
export const macOSCursorSchema: InteractivitySchema = {
...Interactive.baseSchema,
+ ...Interactive.premountSchema,
cursor: {
type: 'enum',
default: 'default',
@@ -50,6 +53,10 @@ const MacOSCursorInner: React.FC<
style,
durationInFrames,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -69,8 +76,13 @@ const MacOSCursorInner: React.FC<
const height = resolved?.height ?? undefined;
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={style ?? null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -82,35 +94,37 @@ const MacOSCursorInner: React.FC<
controls={controls}
outlineRef={refForOutline}
>
- {resolved ? (
- <svg
- ref={refForOutline}
- className={className}
- width={width}
- height={height}
- viewBox={width && height ? `0 0 ${width} ${height}` : undefined}
- xmlns="http://www.w3.org/2000/svg"
- style={{
- display: 'block',
- position: 'absolute',
- width,
- height,
- overflow: 'visible',
- marginLeft: -resolved.hotspot.x,
- marginTop: -resolved.hotspot.y,
- transformOrigin: `${resolved.hotspot.x}px ${resolved.hotspot.y}px`,
- ...style,
- }}
- >
- <image
- href={resolved.src}
+ {(premountingStyle) =>
+ resolved ? (
+ <svg
+ ref={refForOutline}
+ className={className}
width={width}
height={height}
- preserveAspectRatio="xMinYMin meet"
- />
- </svg>
- ) : null}
- </Sequence>
+ viewBox={width && height ? `0 0 ${width} ${height}` : undefined}
+ xmlns="http://www.w3.org/2000/svg"
+ style={{
+ display: 'block',
+ position: 'absolute',
+ width,
+ height,
+ overflow: 'visible',
+ marginLeft: -resolved.hotspot.x,
+ marginTop: -resolved.hotspot.y,
+ transformOrigin: `${resolved.hotspot.x}px ${resolved.hotspot.y}px`,
+ ...premountingStyle,
+ }}
+ >
+ <image
+ href={resolved.src}
+ width={width}
+ height={height}
+ preserveAspectRatio="xMinYMin meet"
+ />
+ </svg>
+ ) : null
+ }
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapHeatmap.tsx b/packages/maptiler/src/MapHeatmap.tsx
index 08dfdc9cdc..545730bd10 100644
--- a/packages/maptiler/src/MapHeatmap.tsx
+++ b/packages/maptiler/src/MapHeatmap.tsx
@@ -5,15 +5,18 @@ import {
} from '@maptiler/sdk';
import {useContext, useEffect, useRef} from 'react';
import {
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type SequenceControls,
useDelayRender,
} from 'remotion';
import {delayMapRender} from './delay-map-render';
import {MapTilerContext} from './MapTilerContext';
+import {useMapPremounting} from './use-map-premounting';
export type MapHeatmapProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> &
Omit<HeatmapLayerOptions, 'layerId' | 'sourceId'> & {
readonly controls?: SequenceControls;
readonly layerId: string;
@@ -43,6 +46,11 @@ const MapHeatmapDrawing = ({
const {map, styleRevision} = useContext(MapTilerContext);
const {continueRender, delayRender} = useDelayRender();
const layerIdsRef = useRef<MapHeatmapLayerIds | null>(null);
+ const applyPremountVisibility = useMapPremounting(() =>
+ Object.entries(layerIdsRef.current ?? {})
+ .filter(([key]) => key.endsWith('LayerId'))
+ .map(([, value]) => value),
+ );
const optionsRef = useRef<HeatmapLayerOptions | null>(null);
const intensityIsDynamic = typeof intensity === 'number';
const opacityIsDynamic = typeof opacity === 'number';
@@ -94,6 +102,7 @@ const MapHeatmapDrawing = ({
};
layerIdsRef.current = helpers.addHeatmap(map, optionsRef.current);
+ applyPremountVisibility();
map.once('idle', finish);
map.triggerRepaint();
@@ -116,7 +125,15 @@ const MapHeatmapDrawing = ({
layerIdsRef.current = null;
map.triggerRepaint();
};
- }, [continueRender, delayRender, layerId, map, structuralKey, styleRevision]);
+ }, [
+ applyPremountVisibility,
+ continueRender,
+ delayRender,
+ layerId,
+ map,
+ structuralKey,
+ styleRevision,
+ ]);
useEffect(() => {
if (!map || typeof data === 'string') {
@@ -187,6 +204,8 @@ export const MapHeatmap = (props: MapHeatmapProps) => {
durationInFrames,
freeze,
from,
+ premountFor,
+ postmountFor,
hidden,
name,
showInTimeline,
@@ -195,8 +214,11 @@ export const MapHeatmap = (props: MapHeatmapProps) => {
} = props;
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -207,7 +229,7 @@ export const MapHeatmap = (props: MapHeatmapProps) => {
showInTimeline={showInTimeline ?? true}
controls={controls}
>
- <MapHeatmapDrawing {...props} />
- </Sequence>
+ {() => <MapHeatmapDrawing {...props} />}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapLayer.tsx b/packages/maptiler/src/MapLayer.tsx
index da5bc442bb..5208e53667 100644
--- a/packages/maptiler/src/MapLayer.tsx
+++ b/packages/maptiler/src/MapLayer.tsx
@@ -1,15 +1,35 @@
import type {LayerSpecification} from '@maptiler/sdk';
-import {useContext, useEffect, useRef} from 'react';
-import {useDelayRender} from 'remotion';
+import {useContext, useEffect, useRef, useMemo} from 'react';
+import {
+ Internals,
+ useDelayRender,
+ type InteractiveBaseProps,
+ type InteractivePremountProps,
+} from 'remotion';
import {MapTilerContext} from './MapTilerContext';
-export type MapLayerProps = {
- readonly beforeId?: string;
- readonly layer: LayerSpecification;
-};
+export type MapLayerProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> & {
+ readonly beforeId?: string;
+ readonly layer: LayerSpecification;
+ };
-export const MapLayer = ({beforeId, layer}: MapLayerProps) => {
+const MapLayerContent = ({beforeId, layer: passedLayer}: MapLayerProps) => {
const {map, styleRevision} = useContext(MapTilerContext);
+ const sequence = useContext(Internals.SequenceContext);
+ const isPremountingOrPostmounting = Boolean(
+ sequence?.premounting || sequence?.postmounting,
+ );
+ const layer = useMemo(
+ (): LayerSpecification =>
+ isPremountingOrPostmounting
+ ? {
+ ...passedLayer,
+ layout: {...passedLayer.layout, visibility: 'none'},
+ }
+ : passedLayer,
+ [isPremountingOrPostmounting, passedLayer],
+ );
const previousLayerRef = useRef<LayerSpecification | null>(null);
const {continueRender, delayRender} = useDelayRender();
@@ -120,3 +140,34 @@ export const MapLayer = ({beforeId, layer}: MapLayerProps) => {
return null;
};
+
+export const MapLayer = ({
+ from,
+ durationInFrames,
+ trimBefore,
+ playbackRate,
+ freeze,
+ hidden,
+ name,
+ showInTimeline,
+ premountFor,
+ postmountFor,
+ ...props
+}: MapLayerProps) => (
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ from={from}
+ durationInFrames={durationInFrames}
+ trimBefore={trimBefore}
+ playbackRate={playbackRate}
+ freeze={freeze}
+ hidden={hidden}
+ showInTimeline={showInTimeline ?? false}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ name={name ?? '<MapLayer>'}
+ >
+ {() => <MapLayerContent {...props} />}
+ </Internals.PremountedSequence>
+);
diff --git a/packages/maptiler/src/MapOverlay.tsx b/packages/maptiler/src/MapOverlay.tsx
index cf6dfb7d23..db45800c85 100644
--- a/packages/maptiler/src/MapOverlay.tsx
+++ b/packages/maptiler/src/MapOverlay.tsx
@@ -8,8 +8,9 @@ import {
} from 'react';
import {
Interactive,
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type InteractiveTransformProps,
type InteractivitySchema,
type SequenceControls,
@@ -28,6 +29,7 @@ export type MapOverlayAnchor =
| 'top-right';
export type MapOverlayProps = InteractiveBaseProps &
+ InteractivePremountProps &
InteractiveTransformProps & {
readonly anchor?: MapOverlayAnchor;
readonly children?: ReactNode;
@@ -43,6 +45,7 @@ export type MapOverlayProps = InteractiveBaseProps &
const mapOverlaySchema = {
...Interactive.baseSchema,
+ ...Interactive.premountSchema,
longitude: {
type: 'number',
min: -180,
@@ -121,6 +124,10 @@ const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<
style,
durationInFrames,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -148,8 +155,13 @@ const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<
useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={{opacity, ...style}}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -161,23 +173,25 @@ const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<
controls={controls}
outlineRef={refForOutline}
>
- <div
- ref={refForOutline}
- style={{
- left: (point?.x ?? 0) + offsetX,
- opacity,
- pointerEvents: 'none',
- position: 'absolute',
- rotate: `${rotation + (rotationAlignment === 'map' ? (map?.getBearing() ?? 0) : 0)}deg`,
- top: (point?.y ?? 0) + offsetY,
- translate: `${horizontalAnchor}% ${verticalAnchor}%`,
- zIndex: 1,
- ...style,
- }}
- >
- {children}
- </div>
- </Sequence>
+ {(premountingStyle) => (
+ <div
+ ref={refForOutline}
+ style={{
+ left: (point?.x ?? 0) + offsetX,
+ opacity,
+ pointerEvents: 'none',
+ position: 'absolute',
+ rotate: `${rotation + (rotationAlignment === 'map' ? (map?.getBearing() ?? 0) : 0)}deg`,
+ top: (point?.y ?? 0) + offsetY,
+ translate: `${horizontalAnchor}% ${verticalAnchor}%`,
+ zIndex: 1,
+ ...premountingStyle,
+ }}
+ >
+ {children}
+ </div>
+ )}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapPoint.tsx b/packages/maptiler/src/MapPoint.tsx
index 35eace5a5e..c253de0acd 100644
--- a/packages/maptiler/src/MapPoint.tsx
+++ b/packages/maptiler/src/MapPoint.tsx
@@ -5,15 +5,18 @@ import {
} from '@maptiler/sdk';
import {useContext, useEffect, useRef} from 'react';
import {
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type SequenceControls,
useDelayRender,
} from 'remotion';
import {delayMapRender} from './delay-map-render';
import {MapTilerContext} from './MapTilerContext';
+import {useMapPremounting} from './use-map-premounting';
export type MapPointProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> &
Omit<PointLayerOptions, 'layerId' | 'sourceId'> & {
readonly controls?: SequenceControls;
readonly layerId: string;
@@ -54,6 +57,11 @@ const MapPointDrawing = ({
const {map, styleRevision} = useContext(MapTilerContext);
const {continueRender, delayRender} = useDelayRender();
const layerIdsRef = useRef<MapPointLayerIds | null>(null);
+ const applyPremountVisibility = useMapPremounting(() =>
+ Object.entries(layerIdsRef.current ?? {})
+ .filter(([key]) => key.endsWith('LayerId'))
+ .map(([, value]) => value),
+ );
const optionsRef = useRef<PointLayerOptions | null>(null);
const outlineColorIsDynamic = typeof outlineColor === 'string';
const outlineOpacityIsDynamic = typeof outlineOpacity === 'number';
@@ -126,6 +134,7 @@ const MapPointDrawing = ({
};
layerIdsRef.current = helpers.addPoint(map, optionsRef.current);
+ applyPremountVisibility();
map.once('idle', finish);
map.triggerRepaint();
@@ -154,7 +163,15 @@ const MapPointDrawing = ({
layerIdsRef.current = null;
map.triggerRepaint();
};
- }, [continueRender, delayRender, layerId, map, structuralKey, styleRevision]);
+ }, [
+ applyPremountVisibility,
+ continueRender,
+ delayRender,
+ layerId,
+ map,
+ structuralKey,
+ styleRevision,
+ ]);
useEffect(() => {
if (!map || typeof data === 'string') {
@@ -261,6 +278,8 @@ export const MapPoint = (props: MapPointProps) => {
durationInFrames,
freeze,
from,
+ premountFor,
+ postmountFor,
hidden,
name,
showInTimeline,
@@ -269,8 +288,11 @@ export const MapPoint = (props: MapPointProps) => {
} = props;
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -281,7 +303,7 @@ export const MapPoint = (props: MapPointProps) => {
showInTimeline={showInTimeline ?? true}
controls={controls}
>
- <MapPointDrawing {...props} />
- </Sequence>
+ {() => <MapPointDrawing {...props} />}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapPolygon.tsx b/packages/maptiler/src/MapPolygon.tsx
index 8b93b6624b..212e5e527d 100644
--- a/packages/maptiler/src/MapPolygon.tsx
+++ b/packages/maptiler/src/MapPolygon.tsx
@@ -5,8 +5,9 @@ import {
} from '@maptiler/sdk';
import {useContext, useEffect, useMemo, useRef} from 'react';
import {
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type SequenceControls,
useDelayRender,
} from 'remotion';
@@ -17,6 +18,7 @@ import {
type MapPolylineFeature,
} from './MapPolyline';
import {MapTilerContext} from './MapTilerContext';
+import {useMapPremounting} from './use-map-premounting';
export type MapPolygonFeature = {
readonly geometry:
@@ -29,6 +31,7 @@ export type MapPolygonFeature = {
export type MapPolygonData = MapPolygonFeature | PolygonLayerOptions['data'];
export type MapPolygonProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> &
Omit<
PolygonLayerOptions,
'data' | 'fillOpacity' | 'layerId' | 'outlinePosition' | 'sourceId'
@@ -118,6 +121,11 @@ const MapPolygonDrawing = ({
const {map, styleRevision} = useContext(MapTilerContext);
const {continueRender, delayRender} = useDelayRender();
const layerIdsRef = useRef<MapPolygonLayerIds | null>(null);
+ const applyPremountVisibility = useMapPremounting(() =>
+ Object.entries(layerIdsRef.current ?? {})
+ .filter(([key]) => key.endsWith('LayerId'))
+ .map(([, value]) => value),
+ );
const optionsRef = useRef<PolygonLayerOptions | null>(null);
const fillColorIsDynamic = typeof fillColor === 'string';
const fillOpacityIsDynamic = typeof fillOpacity === 'number';
@@ -195,6 +203,7 @@ const MapPolygonDrawing = ({
};
layerIdsRef.current = helpers.addPolygon(map, optionsRef.current);
+ applyPremountVisibility();
map.once('idle', finish);
map.triggerRepaint();
@@ -219,7 +228,15 @@ const MapPolygonDrawing = ({
layerIdsRef.current = null;
map.triggerRepaint();
};
- }, [continueRender, delayRender, layerId, map, structuralKey, styleRevision]);
+ }, [
+ applyPremountVisibility,
+ continueRender,
+ delayRender,
+ layerId,
+ map,
+ structuralKey,
+ styleRevision,
+ ]);
useEffect(() => {
if (!map || typeof data === 'string') {
@@ -351,6 +368,8 @@ export const MapPolygon = (props: MapPolygonProps) => {
durationInFrames,
freeze,
from,
+ premountFor,
+ postmountFor,
hidden,
name,
showInTimeline,
@@ -359,8 +378,11 @@ export const MapPolygon = (props: MapPolygonProps) => {
} = props;
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -371,7 +393,7 @@ export const MapPolygon = (props: MapPolygonProps) => {
showInTimeline={showInTimeline ?? true}
controls={controls}
>
- <MapPolygonDrawing {...props} />
- </Sequence>
+ {() => <MapPolygonDrawing {...props} />}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapPolyline.tsx b/packages/maptiler/src/MapPolyline.tsx
index 0abc76b5db..052803946c 100644
--- a/packages/maptiler/src/MapPolyline.tsx
+++ b/packages/maptiler/src/MapPolyline.tsx
@@ -6,13 +6,15 @@ import {
import {length as getLineLength, lineSliceAlong, lineString} from '@turf/turf';
import {useContext, useEffect, useRef, useState} from 'react';
import {
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type SequenceControls,
useDelayRender,
} from 'remotion';
import {delayMapRender} from './delay-map-render';
import {MapTilerContext} from './MapTilerContext';
+import {useMapPremounting} from './use-map-premounting';
export type MapPolylineFeature = {
readonly geometry:
@@ -25,6 +27,7 @@ export type MapPolylineFeature = {
export type MapPolylineData = MapPolylineFeature | PolylineLayerOptions['data'];
export type MapPolylineProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> &
Omit<PolylineLayerOptions, 'data' | 'layerId' | 'sourceId'> & {
readonly controls?: SequenceControls;
readonly data: MapPolylineData;
@@ -141,6 +144,11 @@ const MapPolylineDrawing = ({
const {map, styleRevision} = useContext(MapTilerContext);
const {cancelRender, continueRender, delayRender} = useDelayRender();
const layerIdsRef = useRef<MapPolylineLayerIds | null>(null);
+ const applyPremountVisibility = useMapPremounting(() =>
+ Object.entries(layerIdsRef.current ?? {})
+ .filter(([key]) => key.endsWith('LayerId'))
+ .map(([, value]) => value),
+ );
const optionsRef = useRef<PolylineLayerOptions | null>(null);
const [layerRevision, setLayerRevision] = useState(0);
const lineBlurIsDynamic = typeof lineBlur === 'number';
@@ -233,6 +241,7 @@ const MapPolylineDrawing = ({
}
layerIdsRef.current = ids;
+ applyPremountVisibility();
setLayerRevision((revision) => revision + 1);
map.once('idle', finish);
map.triggerRepaint();
@@ -256,6 +265,7 @@ const MapPolylineDrawing = ({
}
};
}, [
+ applyPremountVisibility,
cancelRender,
continueRender,
delayRender,
@@ -428,6 +438,8 @@ export const MapPolyline = (props: MapPolylineProps) => {
durationInFrames,
freeze,
from,
+ premountFor,
+ postmountFor,
hidden,
name,
showInTimeline,
@@ -436,8 +448,11 @@ export const MapPolyline = (props: MapPolylineProps) => {
} = props;
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -448,7 +463,7 @@ export const MapPolyline = (props: MapPolylineProps) => {
showInTimeline={showInTimeline ?? true}
controls={controls}
>
- <MapPolylineDrawing {...props} />
- </Sequence>
+ {() => <MapPolylineDrawing {...props} />}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapRegion.tsx b/packages/maptiler/src/MapRegion.tsx
index 3499556ed3..6e50aa5052 100644
--- a/packages/maptiler/src/MapRegion.tsx
+++ b/packages/maptiler/src/MapRegion.tsx
@@ -13,13 +13,15 @@ import {
} from 'react';
import {
Interactive,
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type InteractivitySchema,
type SequenceControls,
useDelayRender,
} from 'remotion';
import {MapTilerContext} from './MapTilerContext';
+import {useMapPremounting} from './use-map-premounting';
export type MapRegionFeature = {
type: 'Feature';
@@ -27,20 +29,25 @@ export type MapRegionFeature = {
geometry: {type: 'Polygon'; coordinates: number[][][]};
};
-type MapRegionProps = InteractiveBaseProps & {
- readonly controls?: SequenceControls;
- readonly feature: MapRegionFeature;
- readonly fill?: number;
- readonly fillColor: string;
- readonly glow?: number;
- readonly id: string;
- readonly progress?: number;
- readonly strokeColor?: string;
- readonly strokeWidth?: number;
-};
+type MapRegionProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> & {
+ readonly controls?: SequenceControls;
+ readonly feature: MapRegionFeature;
+ readonly fill?: number;
+ readonly fillColor: string;
+ readonly glow?: number;
+ readonly id: string;
+ readonly progress?: number;
+ readonly strokeColor?: string;
+ readonly strokeWidth?: number;
+ };
const mapRegionSchema = {
...Interactive.baseSchema,
+ ...{
+ premountFor: Interactive.premountSchema.premountFor,
+ postmountFor: Interactive.premountSchema.postmountFor,
+ },
fill: {
type: 'number',
min: 0,
@@ -127,6 +134,11 @@ const MapRegionDrawing = ({
const fillSourceId = `${id}-fill`;
const outlineSourceId = `${id}-outline`;
const outlineGlowLayerId = `${id}-outline-glow`;
+ const applyPremountVisibility = useMapPremounting(() => [
+ fillSourceId,
+ outlineSourceId,
+ outlineGlowLayerId,
+ ]);
useEffect(() => {
if (!map) {
@@ -204,12 +216,14 @@ const MapRegionDrawing = ({
map.setPaintProperty(outlineSourceId, 'line-color', strokeColor);
map.setPaintProperty(outlineSourceId, 'line-width', strokeWidth);
+ applyPremountVisibility();
map.once('idle', () => {
setIsReady(true);
continueRender(loadingHandle);
});
map.triggerRepaint();
}, [
+ applyPremountVisibility,
continueRender,
feature,
fillColor,
@@ -345,6 +359,8 @@ const MapRegionRefForwardingFunction: ForwardRefRenderFunction<
strokeWidth = 9,
durationInFrames,
from,
+ premountFor,
+ postmountFor,
trimBefore,
playbackRate,
freeze,
@@ -360,8 +376,11 @@ const MapRegionRefForwardingFunction: ForwardRefRenderFunction<
useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -373,18 +392,22 @@ const MapRegionRefForwardingFunction: ForwardRefRenderFunction<
controls={controls}
outlineRef={refForOutline}
>
- <MapRegionDrawing
- feature={feature}
- fill={fill}
- fillColor={fillColor}
- glow={glow}
- id={id}
- progress={progress}
- strokeColor={strokeColor}
- strokeWidth={strokeWidth}
- />
- <MapRegionBounds feature={feature} refForOutline={refForOutline} />
- </Sequence>
+ {() => (
+ <>
+ <MapRegionDrawing
+ feature={feature}
+ fill={fill}
+ fillColor={fillColor}
+ glow={glow}
+ id={id}
+ progress={progress}
+ strokeColor={strokeColor}
+ strokeWidth={strokeWidth}
+ />
+ <MapRegionBounds feature={feature} refForOutline={refForOutline} />
+ </>
+ )}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapRoute.tsx b/packages/maptiler/src/MapRoute.tsx
index f3a94bb09d..1751bd8970 100644
--- a/packages/maptiler/src/MapRoute.tsx
+++ b/packages/maptiler/src/MapRoute.tsx
@@ -13,13 +13,15 @@ import {
} from 'react';
import {
Interactive,
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type InteractivitySchema,
type SequenceControls,
useDelayRender,
} from 'remotion';
import {MapTilerContext} from './MapTilerContext';
+import {useMapPremounting} from './use-map-premounting';
export type MapRouteFeature = {
type: 'Feature';
@@ -27,18 +29,23 @@ export type MapRouteFeature = {
geometry: {type: 'LineString'; coordinates: number[][]};
};
-type MapRouteProps = InteractiveBaseProps & {
- readonly controls?: SequenceControls;
- readonly feature: MapRouteFeature;
- readonly glow?: number;
- readonly id: string;
- readonly progress?: number;
- readonly strokeColor?: string;
- readonly strokeWidth?: number;
-};
+type MapRouteProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> & {
+ readonly controls?: SequenceControls;
+ readonly feature: MapRouteFeature;
+ readonly glow?: number;
+ readonly id: string;
+ readonly progress?: number;
+ readonly strokeColor?: string;
+ readonly strokeWidth?: number;
+ };
const mapRouteSchema = {
...Interactive.baseSchema,
+ ...{
+ premountFor: Interactive.premountSchema.premountFor,
+ postmountFor: Interactive.premountSchema.postmountFor,
+ },
glow: {
type: 'number',
min: 0,
@@ -100,6 +107,10 @@ const MapRouteDrawing = ({
const routeLength = useMemo(() => getLineLength(route), [route]);
const sourceId = `${id}-route`;
const glowLayerId = `${id}-route-glow`;
+ const applyPremountVisibility = useMapPremounting(() => [
+ sourceId,
+ glowLayerId,
+ ]);
useEffect(() => {
if (!map) {
@@ -154,12 +165,14 @@ const MapRouteDrawing = ({
map.setPaintProperty(sourceId, 'line-color', strokeColor);
map.setPaintProperty(sourceId, 'line-width', strokeWidth);
+ applyPremountVisibility();
map.once('idle', () => {
setIsReady(true);
continueRender(loadingHandle);
});
map.triggerRepaint();
}, [
+ applyPremountVisibility,
continueRender,
glow,
glowLayerId,
@@ -275,6 +288,8 @@ const MapRouteRefForwardingFunction: ForwardRefRenderFunction<
strokeWidth = 9,
durationInFrames,
from,
+ premountFor,
+ postmountFor,
trimBefore,
playbackRate,
freeze,
@@ -290,8 +305,11 @@ const MapRouteRefForwardingFunction: ForwardRefRenderFunction<
useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -303,16 +321,20 @@ const MapRouteRefForwardingFunction: ForwardRefRenderFunction<
controls={controls}
outlineRef={refForOutline}
>
- <MapRouteDrawing
- feature={feature}
- glow={glow}
- id={id}
- progress={progress}
- strokeColor={strokeColor}
- strokeWidth={strokeWidth}
- />
- <MapRouteBounds feature={feature} refForOutline={refForOutline} />
- </Sequence>
+ {() => (
+ <>
+ <MapRouteDrawing
+ feature={feature}
+ glow={glow}
+ id={id}
+ progress={progress}
+ strokeColor={strokeColor}
+ strokeWidth={strokeWidth}
+ />
+ <MapRouteBounds feature={feature} refForOutline={refForOutline} />
+ </>
+ )}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/maptiler/src/MapSource.tsx b/packages/maptiler/src/MapSource.tsx
index 8bd0355f64..4ec7db3a09 100644
--- a/packages/maptiler/src/MapSource.tsx
+++ b/packages/maptiler/src/MapSource.tsx
@@ -4,17 +4,23 @@ import type {
SourceSpecification,
} from '@maptiler/sdk';
import {useContext, useEffect, useRef, type ReactNode} from 'react';
-import {useDelayRender} from 'remotion';
+import {
+ Internals,
+ useDelayRender,
+ type InteractiveBaseProps,
+ type InteractivePremountProps,
+} from 'remotion';
import {delayMapRender} from './delay-map-render';
import {MapTilerContext} from './MapTilerContext';
-export type MapSourceProps = {
- readonly children?: ReactNode;
- readonly id: string;
- readonly source: SourceSpecification;
-};
+export type MapSourceProps = InteractiveBaseProps &
+ Pick<InteractivePremountProps, 'premountFor' | 'postmountFor'> & {
+ readonly children?: ReactNode;
+ readonly id: string;
+ readonly source: SourceSpecification;
+ };
-export const MapSource = ({children, id, source}: MapSourceProps) => {
+const MapSourceContent = ({children, id, source}: MapSourceProps) => {
const {map, styleRevision} = useContext(MapTilerContext);
const sourceRef = useRef(source);
const {continueRender, delayRender} = useDelayRender();
@@ -86,3 +92,34 @@ export const MapSource = ({children, id, source}: MapSourceProps) => {
return children;
};
+
+export const MapSource = ({
+ from,
+ durationInFrames,
+ trimBefore,
+ playbackRate,
+ freeze,
+ hidden,
+ name,
+ showInTimeline,
+ premountFor,
+ postmountFor,
+ ...props
+}: MapSourceProps) => (
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ from={from}
+ durationInFrames={durationInFrames}
+ trimBefore={trimBefore}
+ playbackRate={playbackRate}
+ freeze={freeze}
+ hidden={hidden}
+ showInTimeline={showInTimeline ?? false}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ name={name ?? '<MapSource>'}
+ >
+ {() => <MapSourceContent {...props} />}
+ </Internals.PremountedSequence>
+);
diff --git a/packages/maptiler/src/MapViewport.tsx b/packages/maptiler/src/MapViewport.tsx
index da228a475b..0baf160691 100644
--- a/packages/maptiler/src/MapViewport.tsx
+++ b/packages/maptiler/src/MapViewport.tsx
@@ -1,6 +1,11 @@
import {Map as MapTilerMap, MapStyle, type MapOptions} from '@maptiler/sdk';
import '@maptiler/sdk/style.css';
-import type {ComponentType, ForwardRefRenderFunction, ReactNode} from 'react';
+import type {
+ ComponentType,
+ CSSProperties,
+ ForwardRefRenderFunction,
+ ReactNode,
+} from 'react';
import {
forwardRef,
useEffect,
@@ -11,8 +16,9 @@ import {
} from 'react';
import {
Interactive,
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type InteractivitySchema,
type SequenceControls,
useDelayRender,
@@ -39,30 +45,31 @@ export type MapViewportMapOptions = Omit<
export type MapAdministrativeBorders = 'all' | 'country-only' | 'none';
-export type MapViewportProps = InteractiveBaseProps & {
- readonly apiKey: string | null;
- readonly backgroundColor?: string;
- readonly bearing?: number;
- readonly centerLatitude?: number;
- readonly centerLongitude?: number;
- readonly children?: ReactNode;
- readonly controls?: SequenceControls;
- readonly language?: MapOptions['language'];
- readonly mapOptions?: MapViewportMapOptions;
- readonly mapStyle?: MapOptions['style'];
- readonly onMapReady?: (map: MapTilerMap) => void;
- readonly paddingBottom?: number;
- readonly paddingLeft?: number;
- readonly paddingRight?: number;
- readonly paddingTop?: number;
- readonly pitch?: number;
- readonly projection?: MapOptions['projection'];
- readonly showLabels?: boolean;
- readonly administrativeBorders?: MapAdministrativeBorders;
- readonly terrain?: boolean;
- readonly terrainExaggeration?: number;
- readonly zoom?: number;
-};
+export type MapViewportProps = InteractiveBaseProps &
+ InteractivePremountProps & {
+ readonly apiKey: string | null;
+ readonly backgroundColor?: string;
+ readonly bearing?: number;
+ readonly centerLatitude?: number;
+ readonly centerLongitude?: number;
+ readonly children?: ReactNode;
+ readonly controls?: SequenceControls;
+ readonly language?: MapOptions['language'];
+ readonly mapOptions?: MapViewportMapOptions;
+ readonly mapStyle?: MapOptions['style'];
+ readonly onMapReady?: (map: MapTilerMap) => void;
+ readonly paddingBottom?: number;
+ readonly paddingLeft?: number;
+ readonly paddingRight?: number;
+ readonly paddingTop?: number;
+ readonly pitch?: number;
+ readonly projection?: MapOptions['projection'];
+ readonly showLabels?: boolean;
+ readonly administrativeBorders?: MapAdministrativeBorders;
+ readonly terrain?: boolean;
+ readonly terrainExaggeration?: number;
+ readonly zoom?: number;
+ };
const stripStyleLayers = ({
administrativeBorders,
@@ -88,6 +95,7 @@ const stripStyleLayers = ({
const mapViewportSchema = {
...Interactive.baseSchema,
+ ...Interactive.premountSchema,
centerLongitude: {
type: 'number',
min: -180,
@@ -209,12 +217,15 @@ const MissingApiKey = () => {
);
};
-const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
+const MapViewportContentRefForwardingFunction: ForwardRefRenderFunction<
HTMLDivElement,
- MapViewportProps
+ MapViewportProps & {
+ readonly premountingStyle: CSSProperties | null;
+ }
> = (
{
apiKey,
+ premountingStyle,
backgroundColor = '#dfe7e2',
bearing = 0,
centerLatitude = 0,
@@ -234,16 +245,7 @@ const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
administrativeBorders = 'all',
terrain = false,
terrainExaggeration = 1,
- durationInFrames,
- from,
- trimBefore,
- playbackRate,
- freeze,
- hidden,
- name,
- showInTimeline,
zoom = 4,
- controls,
},
ref,
) => {
@@ -509,48 +511,86 @@ const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
}, [map, projection]);
return (
- <Sequence
- layout="none"
- from={from ?? 0}
- trimBefore={trimBefore}
- playbackRate={playbackRate}
- durationInFrames={durationInFrames ?? Infinity}
- freeze={freeze}
- hidden={hidden}
- name={name ?? '<MapViewport>'}
- showInTimeline={showInTimeline ?? true}
- controls={controls}
+ <div
+ ref={viewportRef}
+ style={{
+ backgroundColor,
+ inset: 0,
+ overflow: 'hidden',
+ position: 'absolute',
+ ...premountingStyle,
+ }}
>
- <div
- ref={viewportRef}
- style={{
- backgroundColor,
- inset: 0,
- overflow: 'hidden',
- position: 'absolute',
- }}
- >
- {apiKey ? (
- <>
- <div
- ref={mapContainerRef}
- style={{
- inset: 0,
- position: 'absolute',
- }}
- />
- <MapTilerContext.Provider value={contextValue}>
- {children}
- </MapTilerContext.Provider>
- </>
- ) : (
- <MissingApiKey />
- )}
- </div>
- </Sequence>
+ {apiKey ? (
+ <>
+ <div
+ ref={mapContainerRef}
+ style={{
+ inset: 0,
+ position: 'absolute',
+ }}
+ />
+ <MapTilerContext.Provider value={contextValue}>
+ {children}
+ </MapTilerContext.Provider>
+ </>
+ ) : (
+ <MissingApiKey />
+ )}
+ </div>
);
};
+const MapViewportContent = forwardRef(MapViewportContentRefForwardingFunction);
+const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
+ HTMLDivElement,
+ MapViewportProps
+> = (
+ {
+ durationInFrames,
+ from,
+ trimBefore,
+ playbackRate,
+ freeze,
+ hidden,
+ name,
+ showInTimeline,
+ controls,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
+ ...props
+ },
+ ref,
+) => (
+ <Internals.PremountedSequence
+ style={null}
+ hideWhilePremounted="opacity"
+ durationInFrames={durationInFrames}
+ from={from}
+ trimBefore={trimBefore}
+ playbackRate={playbackRate}
+ freeze={freeze}
+ hidden={hidden}
+ showInTimeline={showInTimeline}
+ controls={controls}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
+ name={name ?? '<MapViewport>'}
+ >
+ {(premountingStyle) => (
+ <MapViewportContent
+ {...props}
+ ref={ref}
+ premountingStyle={premountingStyle}
+ />
+ )}
+ </Internals.PremountedSequence>
+);
+
const MapViewportInner = forwardRef(MapViewportRefForwardingFunction);
export const MapViewport: ComponentType<MapViewportProps> =
diff --git a/packages/maptiler/src/use-map-premounting.ts b/packages/maptiler/src/use-map-premounting.ts
new file mode 100644
index 0000000000..07d0aada26
--- /dev/null
+++ b/packages/maptiler/src/use-map-premounting.ts
@@ -0,0 +1,38 @@
+import {useCallback, useContext, useEffect, useRef} from 'react';
+import {Internals} from 'remotion';
+import {MapTilerContext} from './MapTilerContext';
+
+// Generated layers have no DOM element to hide. Also apply this immediately
+// after asynchronous layer creation, using the latest sequence state.
+export const useMapPremounting = (getLayerIds: () => string[]) => {
+ const {map} = useContext(MapTilerContext);
+ const sequence = useContext(Internals.SequenceContext);
+ const hidden = Boolean(sequence?.premounting || sequence?.postmounting);
+ const hiddenRef = useRef(hidden);
+ const layerIdsRef = useRef(getLayerIds);
+ hiddenRef.current = hidden;
+ layerIdsRef.current = getLayerIds;
+
+ const applyPremountVisibility = useCallback(() => {
+ if (!map) {
+ return;
+ }
+
+ for (const id of layerIdsRef.current()) {
+ if (!id || !map.getLayer(id)) {
+ continue;
+ }
+
+ const visibility = hiddenRef.current ? 'none' : 'visible';
+ if (map.getLayoutProperty(id, 'visibility') !== visibility) {
+ map.setLayoutProperty(id, 'visibility', visibility);
+ }
+ }
+ }, [map]);
+
+ useEffect(() => {
+ applyPremountVisibility();
+ }, [applyPremountVisibility, hidden]);
+
+ return applyPremountVisibility;
+};
diff --git a/packages/rive/src/RemotionRiveCanvas.tsx b/packages/rive/src/RemotionRiveCanvas.tsx
index 85be4525e3..24bbb5a05d 100644
--- a/packages/rive/src/RemotionRiveCanvas.tsx
+++ b/packages/rive/src/RemotionRiveCanvas.tsx
@@ -18,6 +18,7 @@ import React, {
import type {
EffectsProp,
InteractiveBaseProps,
+ InteractivePremountProps,
InteractiveCropProps,
SequenceControls,
InteractivitySchema,
@@ -25,7 +26,6 @@ import type {
import {
Internals,
Interactive,
- Sequence,
useCurrentFrame,
useDelayRender,
useVideoConfig,
@@ -62,6 +62,7 @@ type RemotionRiveCanvasOwnProps = {
export type RemotionRiveCanvasProps = RemotionRiveCanvasOwnProps &
InteractiveBaseProps &
+ InteractivePremountProps &
InteractiveCropProps;
export type RiveCanvasRef = {
@@ -98,6 +99,7 @@ const riveAlignmentVariants: Record<
export const riveCanvasSchema: InteractivitySchema = {
...Internals.baseSchema,
+ ...Internals.premountSchema,
fit: {
type: 'enum',
default: 'contain',
@@ -441,6 +443,10 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<
durationInFrames,
name,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -468,8 +474,13 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<
});
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={croppedStyle}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -488,23 +499,25 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<
outlineRef={canvasRef}
{...props}
>
- <RemotionRiveCanvasContent
- ref={ref}
- src={src}
- fit={fit}
- alignment={alignment}
- artboard={artboard}
- animation={animation}
- onLoad={onLoad}
- assetLoader={assetLoader}
- enableRiveAssetCdn={enableRiveAssetCdn}
- className={className}
- style={croppedStyle ?? undefined}
- effects={effects}
- controls={controls}
- canvasRef={canvasRef}
- />
- </Sequence>
+ {(premountingStyle) => (
+ <RemotionRiveCanvasContent
+ ref={ref}
+ src={src}
+ fit={fit}
+ alignment={alignment}
+ artboard={artboard}
+ animation={animation}
+ onLoad={onLoad}
+ assetLoader={assetLoader}
+ enableRiveAssetCdn={enableRiveAssetCdn}
+ className={className}
+ style={premountingStyle ?? undefined}
+ effects={effects}
+ controls={controls}
+ canvasRef={canvasRef}
+ />
+ )}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/rough-notation/src/Annotation.tsx b/packages/rough-notation/src/Annotation.tsx
index 4b96cb4da4..5ff692a243 100644
--- a/packages/rough-notation/src/Annotation.tsx
+++ b/packages/rough-notation/src/Annotation.tsx
@@ -1,8 +1,9 @@
import React, {useMemo} from 'react';
import {
Interactive,
- Sequence,
+ Internals,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type InteractivitySchema,
type SequenceControls,
} from 'remotion';
@@ -34,7 +35,8 @@ type SharedAnnotationComponentProps = Readonly<
type AnnotationInteractiveProps<Config> = SharedAnnotationComponentProps &
Readonly<Config> &
- InteractiveBaseProps;
+ InteractiveBaseProps &
+ InteractivePremountProps;
export type HighlightProps = AnnotationInteractiveProps<HighlightConfig>;
export type UnderlineProps = AnnotationInteractiveProps<UnderlineConfig>;
@@ -48,7 +50,8 @@ export type CircleProps = AnnotationInteractiveProps<
>;
type InternalAnnotationProps = SharedAnnotationComponentProps &
- InteractiveBaseProps & {
+ InteractiveBaseProps &
+ InteractivePremountProps & {
readonly color?: string;
readonly strokeWidth?: number;
readonly padding?: Partial<Padding>;
@@ -210,6 +213,7 @@ const textContentSchema = {
const sharedSchema = (defaultRoughness: number): InteractivitySchema => ({
...Interactive.baseSchema,
+ ...Interactive.premountSchema,
progress: {
type: 'number',
min: 0,
@@ -356,6 +360,10 @@ const makeAnnotationComponent = ({
children,
durationInFrames,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
trimBefore,
playbackRate,
freeze,
@@ -401,8 +409,13 @@ const makeAnnotationComponent = ({
);
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={null}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from ?? 0}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -415,17 +428,23 @@ const makeAnnotationComponent = ({
_remotionInternalDocumentationLink={`https://www.remotion.dev/docs/rough-notation/${documentationSlug}`}
outlineRef={outlineRef}
>
- <span
- ref={outlineRef}
- style={{display: 'inline-block', position: 'relative'}}
- >
- <annotation.Container>
- {layer === 'behind' ? annotationElement : null}
- <annotation.Tracker style={style}>{children}</annotation.Tracker>
- {layer === 'on-top' ? annotationElement : null}
- </annotation.Container>
- </span>
- </Sequence>
+ {(premountingStyle) => (
+ <span
+ ref={outlineRef}
+ style={{
+ display: 'inline-block',
+ position: 'relative',
+ ...premountingStyle,
+ }}
+ >
+ <annotation.Container>
+ {layer === 'behind' ? annotationElement : null}
+ <annotation.Tracker style={style}>{children}</annotation.Tracker>
+ {layer === 'on-top' ? annotationElement : null}
+ </annotation.Container>
+ </span>
+ )}
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/shapes/src/components/render-svg.tsx b/packages/shapes/src/components/render-svg.tsx
index 31941946a7..c63eb8aa12 100644
--- a/packages/shapes/src/components/render-svg.tsx
+++ b/packages/shapes/src/components/render-svg.tsx
@@ -4,18 +4,19 @@ import {version} from 'react-dom';
import {
HtmlInCanvas,
Internals,
- Sequence,
type EffectsProp,
type HtmlInCanvasPixelDensity,
type HtmlInCanvasProps,
type InteractiveBaseProps,
+ type InteractivePremountProps,
type SequenceControls,
} from 'remotion';
import {doesReactSupportTransformOriginProperty} from '../utils/does-react-support-canary';
-type ShapeSequenceProps = InteractiveBaseProps & {
- readonly controls?: SequenceControls;
-};
+type ShapeSequenceProps = InteractiveBaseProps &
+ InteractivePremountProps & {
+ readonly controls?: SequenceControls;
+ };
const HtmlInCanvasWithPrivateProps = HtmlInCanvas as React.ComponentType<
HtmlInCanvasProps & {
@@ -50,6 +51,11 @@ export const RenderSvg = ({
pixelDensity,
durationInFrames,
from,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
+
trimBefore,
playbackRate,
freeze,
@@ -210,8 +216,13 @@ export const RenderSvg = ({
}
return (
- <Sequence
- layout="none"
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={actualStyle}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
from={from}
trimBefore={trimBefore}
playbackRate={playbackRate}
@@ -227,7 +238,9 @@ export const RenderSvg = ({
name === undefined ? documentationLink : undefined
}
>
- {content}
- </Sequence>
+ {(premountingStyle) =>
+ React.cloneElement(content, {style: premountingStyle ?? undefined})
+ }
+ </Internals.PremountedSequence>
);
};
diff --git a/packages/shapes/src/components/schema.ts b/packages/shapes/src/components/schema.ts
index 9d77e513be..8f1b60af6a 100644
--- a/packages/shapes/src/components/schema.ts
+++ b/packages/shapes/src/components/schema.ts
@@ -83,6 +83,7 @@ export const makeShapeSchema = (
): InteractivitySchema => {
return {
...Internals.baseSchema,
+ ...Internals.premountSchema,
...shapeFields,
fill: colorField({
defaultValue: '#0b84ff',
diff --git a/packages/three/src/ThreeCanvas.tsx b/packages/three/src/ThreeCanvas.tsx
index e14b1c9046..4238234c3e 100644
--- a/packages/three/src/ThreeCanvas.tsx
+++ b/packages/three/src/ThreeCanvas.tsx
@@ -9,6 +9,8 @@ import React, {
} from 'react';
import {
Internals,
+ type InteractiveBaseProps,
+ type InteractivePremountProps,
useCurrentFrame,
useDelayRender,
useRemotionEnvironment,
@@ -16,11 +18,16 @@ import {
import {SuspenseLoader} from './SuspenseLoader';
import {validateDimension} from './validate';
-export type ThreeCanvasProps = React.ComponentProps<typeof Canvas> & {
- readonly width: number;
- readonly height: number;
- readonly children: React.ReactNode;
-};
+export type ThreeCanvasProps = Omit<
+ React.ComponentProps<typeof Canvas>,
+ keyof InteractiveBaseProps
+> &
+ InteractiveBaseProps &
+ InteractivePremountProps & {
+ readonly width: number;
+ readonly height: number;
+ readonly children: React.ReactNode;
+ };
export type ThreeCanvasFrameRendererProps = {
readonly onRendered: () => void;
@@ -60,7 +67,7 @@ const ManualFrameRenderer = ({onRendered}: ThreeCanvasFrameRendererProps) => {
return null;
};
-export const ThreeCanvasInternals = (props: ThreeCanvasInternalsProps) => {
+const ThreeCanvasContent = (props: ThreeCanvasInternalsProps) => {
const {
children,
width,
@@ -146,6 +153,46 @@ export const ThreeCanvasInternals = (props: ThreeCanvasInternalsProps) => {
);
};
+export const ThreeCanvasInternals = ({
+ from,
+ durationInFrames,
+ trimBefore,
+ playbackRate,
+ freeze,
+ hidden,
+ name,
+ showInTimeline,
+ premountFor,
+ postmountFor,
+ styleWhilePremounted,
+ styleWhilePostmounted,
+ style,
+ ...props
+}: ThreeCanvasInternalsProps) => {
+ return (
+ <Internals.PremountedSequence
+ hideWhilePremounted="opacity"
+ style={style ?? null}
+ from={from}
+ durationInFrames={durationInFrames}
+ trimBefore={trimBefore}
+ playbackRate={playbackRate}
+ freeze={freeze}
+ hidden={hidden}
+ premountFor={premountFor}
+ postmountFor={postmountFor}
+ styleWhilePremounted={styleWhilePremounted}
+ styleWhilePostmounted={styleWhilePostmounted}
+ name={name ?? '<ThreeCanvas>'}
+ showInTimeline={showInTimeline ?? false}
+ >
+ {(premountingStyle) => (
+ <ThreeCanvasContent {...props} style={premountingStyle ?? undefined} />
+ )}
+ </Internals.PremountedSequence>
+ );
+};
+
/*
* @description A wrapper for React Three Fiber's <Canvas /> which synchronizes with Remotion's useCurrentFrame().
* @see [Documentation](https://www.remotion.dev/docs/three-canvas)