Skip to content

🎥 Make videos programmatically with React

Simplify Interactive.withSchema component layers

JonnyBurger2206e54b5d9d
diff --git a/packages/codemods/src/basic-captions-element-source.ts b/packages/codemods/src/basic-captions-element-source.ts
index af824ce25a..14989598bd 100644
--- a/packages/codemods/src/basic-captions-element-source.ts
+++ b/packages/codemods/src/basic-captions-element-source.ts
@@ -18,10 +18,13 @@ type BasicCaptionsProps = InteractiveTransformProps &
readonly combineTokensWithinMilliseconds?: number;
};
-const BasicCaptionsContent: React.FC<{
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
-}> = ({captions, combineTokensWithinMilliseconds}) => {
+const BasicCaptionsContent: React.FC<BasicCaptionsProps> = ({
+ captions,
+ combineTokensWithinMilliseconds = 2000,
+ height = 220,
+ style,
+ width = 900,
+}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const pages = useMemo(
@@ -39,30 +42,43 @@ const BasicCaptionsContent: React.FC<{
currentTimeMs < candidate.startMs + candidate.durationMs,
);
- if (!page) {
- return null;
- }
-
return (
<div
style={{
- backgroundColor: 'rgba(64, 64, 64, 0.75)',
- color: '#ffffff',
- display: '-webkit-box',
- fontFamily: 'Arial, Helvetica, sans-serif',
- fontSize: 64,
- fontWeight: 400,
- lineHeight: 1.2,
- overflow: 'hidden',
- padding: '14px 22px',
- textAlign: 'center',
- textWrap: 'balance',
- WebkitBoxOrient: 'vertical',
- WebkitLineClamp: 2,
- whiteSpace: 'pre-wrap',
+ alignItems: 'center',
+ display: 'flex',
+ justifyContent: 'center',
+ position: 'absolute',
+ bottom: 120,
+ left: '50%',
+ transform: 'translateX(-50%)',
+ width,
+ height,
+ ...style,
}}
>
- {page.text.trim()}
+ {page ? (
+ <div
+ style={{
+ backgroundColor: 'rgba(64, 64, 64, 0.75)',
+ color: '#ffffff',
+ display: '-webkit-box',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 64,
+ fontWeight: 400,
+ lineHeight: 1.2,
+ overflow: 'hidden',
+ padding: '14px 22px',
+ textAlign: 'center',
+ textWrap: 'balance',
+ WebkitBoxOrient: 'vertical',
+ WebkitLineClamp: 2,
+ whiteSpace: 'pre-wrap',
+ }}
+ >
+ {page.text.trim()}
+ </div>
+ ) : null}
</div>
);
};
@@ -96,38 +112,8 @@ const basicCaptionsSchema = {
...Interactive.transformSchema,
} as const satisfies InteractivitySchema;
-const BasicCaptionsInner: React.FC<BasicCaptionsProps> = ({
- captions,
- combineTokensWithinMilliseconds = 2000,
- height = 220,
- style,
- width = 900,
-}) => {
- return (
- <div
- style={{
- alignItems: 'center',
- display: 'flex',
- justifyContent: 'center',
- position: 'absolute',
- bottom: 120,
- left: '50%',
- transform: 'translateX(-50%)',
- width,
- height,
- ...style,
- }}
- >
- <BasicCaptionsContent
- captions={captions}
- combineTokensWithinMilliseconds={combineTokensWithinMilliseconds}
- />
- </div>
- );
-};
-
export const BasicCaptions = Interactive.withSchema({
- Component: BasicCaptionsInner,
+ Component: BasicCaptionsContent,
componentName: '<BasicCaptions>',
defaultSequenceName: 'Basic captions',
schema: basicCaptionsSchema,
diff --git a/packages/docs/elements/audio/mirrored-spectrum/mirrored-spectrum.tsx b/packages/docs/elements/audio/mirrored-spectrum/mirrored-spectrum.tsx
index 305fd890e7..8178364dbc 100644
--- a/packages/docs/elements/audio/mirrored-spectrum/mirrored-spectrum.tsx
+++ b/packages/docs/elements/audio/mirrored-spectrum/mirrored-spectrum.tsx
@@ -51,13 +51,13 @@ const mirroredAudioSpectrumSchema = {
...Interactive.transformSchema,
} as const satisfies InteractivitySchema;
-const MirroredAudioSpectrumContent: React.FC<{
- readonly audioSrc: string;
- readonly barColor: string;
- readonly numberOfBars: number;
- readonly sensitivity: number;
- readonly style: MirroredAudioSpectrumProps['style'];
-}> = ({audioSrc, barColor, numberOfBars, sensitivity, style}) => {
+const MirroredAudioSpectrumInner: React.FC<MirroredAudioSpectrumProps> = ({
+ audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
+ barColor = '#2563eb',
+ numberOfBars = 65,
+ sensitivity = 1.5,
+ style,
+}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const {audioData, dataOffsetInSeconds} = useWindowedAudioData({
@@ -120,24 +120,6 @@ const MirroredAudioSpectrumContent: React.FC<{
);
};
-const MirroredAudioSpectrumInner: React.FC<MirroredAudioSpectrumProps> = ({
- audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
- barColor = '#2563eb',
- numberOfBars = 65,
- sensitivity = 1.5,
- style,
-}) => {
- return (
- <MirroredAudioSpectrumContent
- audioSrc={audioSrc}
- barColor={barColor}
- numberOfBars={numberOfBars}
- sensitivity={sensitivity}
- style={style}
- />
- );
-};
-
export const MirroredAudioSpectrum = Interactive.withSchema({
Component: MirroredAudioSpectrumInner,
componentName: '<MirroredAudioSpectrum>',
diff --git a/packages/docs/elements/audio/oscilloscope/audio-oscilloscope.tsx b/packages/docs/elements/audio/oscilloscope/audio-oscilloscope.tsx
index d9a2f98e89..fb6e2bab44 100644
--- a/packages/docs/elements/audio/oscilloscope/audio-oscilloscope.tsx
+++ b/packages/docs/elements/audio/oscilloscope/audio-oscilloscope.tsx
@@ -64,14 +64,14 @@ const audioOscilloscopeSchema = {
...Interactive.transformSchema,
} as const satisfies InteractivitySchema;
-const AudioOscilloscopeContent: React.FC<{
- readonly amplitude: number;
- readonly audioSrc: string;
- readonly lineColor: string;
- readonly lineWidth: number;
- readonly style: AudioOscilloscopeProps['style'];
- readonly windowInSeconds: number;
-}> = ({amplitude, audioSrc, lineColor, lineWidth, style, windowInSeconds}) => {
+const AudioOscilloscopeInner: React.FC<AudioOscilloscopeProps> = ({
+ amplitude = 2,
+ audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
+ lineColor = '#2563eb',
+ lineWidth = 6,
+ style,
+ windowInSeconds = 0.35,
+}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const {audioData, dataOffsetInSeconds} = useWindowedAudioData({
@@ -136,26 +136,6 @@ const AudioOscilloscopeContent: React.FC<{
);
};
-const AudioOscilloscopeInner: React.FC<AudioOscilloscopeProps> = ({
- amplitude = 2,
- audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
- lineColor = '#2563eb',
- lineWidth = 6,
- style,
- windowInSeconds = 0.35,
-}) => {
- return (
- <AudioOscilloscopeContent
- amplitude={amplitude}
- audioSrc={audioSrc}
- lineColor={lineColor}
- lineWidth={lineWidth}
- style={style}
- windowInSeconds={windowInSeconds}
- />
- );
-};
-
export const AudioOscilloscope = Interactive.withSchema({
Component: AudioOscilloscopeInner,
componentName: '<AudioOscilloscope>',
diff --git a/packages/docs/elements/captions/basic-captions/basic-captions.tsx b/packages/docs/elements/captions/basic-captions/basic-captions.tsx
index 9c7bedb33d..740f377ae9 100644
--- a/packages/docs/elements/captions/basic-captions/basic-captions.tsx
+++ b/packages/docs/elements/captions/basic-captions/basic-captions.tsx
@@ -49,10 +49,13 @@ const basicCaptionsSchema = {
...Interactive.transformSchema,
} as const satisfies InteractivitySchema;
-const BasicCaptionsContent: React.FC<{
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
-}> = ({captions, combineTokensWithinMilliseconds}) => {
+const BasicCaptionsContent: React.FC<BasicCaptionsProps> = ({
+ captions,
+ combineTokensWithinMilliseconds = defaultCombineTokensWithinMilliseconds,
+ height = defaultHeight,
+ style,
+ width = defaultWidth,
+}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const pages = useMemo(
@@ -70,41 +73,6 @@ const BasicCaptionsContent: React.FC<{
currentTimeMs < candidate.startMs + candidate.durationMs,
);
- if (!page) {
- return null;
- }
-
- return (
- <div
- style={{
- backgroundColor: 'rgba(64, 64, 64, 0.75)',
- color: '#ffffff',
- display: '-webkit-box',
- fontFamily: 'Arial, Helvetica, sans-serif',
- fontSize: 64,
- fontWeight: 400,
- lineHeight: 1.2,
- overflow: 'hidden',
- padding: '14px 22px',
- textAlign: 'center',
- textWrap: 'balance',
- WebkitBoxOrient: 'vertical',
- WebkitLineClamp: 2,
- whiteSpace: 'pre-wrap',
- }}
- >
- {page.text.trim()}
- </div>
- );
-};
-
-const BasicCaptionsInner: React.FC<BasicCaptionsProps> = ({
- captions,
- combineTokensWithinMilliseconds = defaultCombineTokensWithinMilliseconds,
- height = defaultHeight,
- style,
- width = defaultWidth,
-}) => {
return (
<div
style={{
@@ -117,19 +85,35 @@ const BasicCaptionsInner: React.FC<BasicCaptionsProps> = ({
...style,
}}
>
- <BasicCaptionsContent
- captions={captions}
- combineTokensWithinMilliseconds={combineTokensWithinMilliseconds}
- />
+ {page ? (
+ <div
+ style={{
+ backgroundColor: 'rgba(64, 64, 64, 0.75)',
+ color: '#ffffff',
+ display: '-webkit-box',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 64,
+ fontWeight: 400,
+ lineHeight: 1.2,
+ overflow: 'hidden',
+ padding: '14px 22px',
+ textAlign: 'center',
+ textWrap: 'balance',
+ WebkitBoxOrient: 'vertical',
+ WebkitLineClamp: 2,
+ whiteSpace: 'pre-wrap',
+ }}
+ >
+ {page.text.trim()}
+ </div>
+ ) : null}
</div>
);
};
-const BasicCaptionsLayer = Interactive.withSchema({
- Component: BasicCaptionsInner,
+export const BasicCaptions = Interactive.withSchema({
+ Component: BasicCaptionsContent,
componentName: '<BasicCaptions>',
schema: basicCaptionsSchema,
wrapInSequence: true,
});
-
-export const BasicCaptions = BasicCaptionsLayer;
diff --git a/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx b/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx
index 62ad44423e..feaf6724b4 100644
--- a/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx
+++ b/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx
@@ -319,48 +319,7 @@ const CaptionPage: React.FC<{
);
};
-const MovingPillCaptionsContent: React.FC<{
- readonly captionAreaWidth: number | null;
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
- readonly fontLoaded: boolean;
-}> = ({
- captionAreaWidth,
- captions,
- combineTokensWithinMilliseconds,
- fontLoaded,
-}) => {
- const frame = useCurrentFrame();
- const {fps} = useVideoConfig();
- const pages = useMemo(
- () =>
- createTikTokStyleCaptions({
- captions,
- combineTokensWithinMilliseconds,
- }).pages,
- [captions, combineTokensWithinMilliseconds],
- );
- const currentTimeMs = (frame / fps) * 1000;
- const activePageIndex = getActivePageIndex(pages, currentTimeMs);
- const page = pages[activePageIndex];
-
- if (!fontLoaded || !page) {
- return null;
- }
-
- return (
- <CaptionPage
- key={`${activePageIndex}-${page.startMs}`}
- captionAreaWidth={captionAreaWidth}
- currentTimeMs={currentTimeMs}
- fps={fps}
- page={page}
- pageIndex={activePageIndex}
- />
- );
-};
-
-const MovingPillCaptionsInner: React.FC<MovingPillCaptionsProps> = ({
+const MovingPillCaptionsContent: React.FC<MovingPillCaptionsProps> = ({
captions,
combineTokensWithinMilliseconds = defaultCombineTokensWithinMilliseconds,
height = defaultHeight,
@@ -379,6 +338,20 @@ const MovingPillCaptionsInner: React.FC<MovingPillCaptionsProps> = ({
});
}, []);
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const pages = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds,
+ }).pages,
+ [captions, combineTokensWithinMilliseconds],
+ );
+ const currentTimeMs = (frame / fps) * 1000;
+ const activePageIndex = getActivePageIndex(pages, currentTimeMs);
+ const page = pages[activePageIndex];
+
return (
<div
style={{
@@ -388,21 +361,23 @@ const MovingPillCaptionsInner: React.FC<MovingPillCaptionsProps> = ({
...style,
}}
>
- <MovingPillCaptionsContent
- captionAreaWidth={width ?? null}
- captions={captions}
- combineTokensWithinMilliseconds={combineTokensWithinMilliseconds}
- fontLoaded={fontLoaded}
- />
+ {fontLoaded && page ? (
+ <CaptionPage
+ key={`${activePageIndex}-${page.startMs}`}
+ captionAreaWidth={width ?? null}
+ currentTimeMs={currentTimeMs}
+ fps={fps}
+ page={page}
+ pageIndex={activePageIndex}
+ />
+ ) : null}
</div>
);
};
-const MovingPillCaptionsLayer = Interactive.withSchema({
- Component: MovingPillCaptionsInner,
+export const MovingPillCaptions = Interactive.withSchema({
+ Component: MovingPillCaptionsContent,
componentName: '<MovingPillCaptions>',
schema: movingPillCaptionsSchema,
wrapInSequence: true,
});
-
-export const MovingPillCaptions = MovingPillCaptionsLayer;
diff --git a/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx b/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx
index 58b604c572..1eac2ac1ee 100644
--- a/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx
+++ b/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx
@@ -225,48 +225,7 @@ const CaptionPage: React.FC<{
);
};
-const PoppingWordCaptionsContent: React.FC<{
- readonly captionAreaWidth: number | null;
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
- readonly fontLoaded: boolean;
-}> = ({
- captionAreaWidth,
- captions,
- combineTokensWithinMilliseconds,
- fontLoaded,
-}) => {
- const frame = useCurrentFrame();
- const {fps} = useVideoConfig();
- const pages = useMemo(
- () =>
- createTikTokStyleCaptions({
- captions,
- combineTokensWithinMilliseconds,
- }).pages,
- [captions, combineTokensWithinMilliseconds],
- );
- const currentTimeMs = (frame / fps) * 1000;
- const activePageIndex = getActivePageIndex(pages, currentTimeMs);
- const page = pages[activePageIndex];
-
- if (!fontLoaded || !page) {
- return null;
- }
-
- return (
- <CaptionPage
- key={`${activePageIndex}-${page.startMs}`}
- captionAreaWidth={captionAreaWidth}
- currentTimeMs={currentTimeMs}
- fps={fps}
- page={page}
- pageIndex={activePageIndex}
- />
- );
-};
-
-const PoppingWordCaptionsInner: React.FC<PoppingWordCaptionsProps> = ({
+const PoppingWordCaptionsContent: React.FC<PoppingWordCaptionsProps> = ({
captions,
combineTokensWithinMilliseconds = defaultCombineTokensWithinMilliseconds,
height = defaultHeight,
@@ -285,6 +244,20 @@ const PoppingWordCaptionsInner: React.FC<PoppingWordCaptionsProps> = ({
});
}, []);
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const pages = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds,
+ }).pages,
+ [captions, combineTokensWithinMilliseconds],
+ );
+ const currentTimeMs = (frame / fps) * 1000;
+ const activePageIndex = getActivePageIndex(pages, currentTimeMs);
+ const page = pages[activePageIndex];
+
return (
<div
style={{
@@ -294,21 +267,23 @@ const PoppingWordCaptionsInner: React.FC<PoppingWordCaptionsProps> = ({
...style,
}}
>
- <PoppingWordCaptionsContent
- captionAreaWidth={width ?? null}
- captions={captions}
- combineTokensWithinMilliseconds={combineTokensWithinMilliseconds}
- fontLoaded={fontLoaded}
- />
+ {fontLoaded && page ? (
+ <CaptionPage
+ key={`${activePageIndex}-${page.startMs}`}
+ captionAreaWidth={width ?? null}
+ currentTimeMs={currentTimeMs}
+ fps={fps}
+ page={page}
+ pageIndex={activePageIndex}
+ />
+ ) : null}
</div>
);
};
-const PoppingWordCaptionsLayer = Interactive.withSchema({
- Component: PoppingWordCaptionsInner,
+export const PoppingWordCaptions = Interactive.withSchema({
+ Component: PoppingWordCaptionsContent,
componentName: '<PoppingWordCaptions>',
schema: poppingWordCaptionsSchema,
wrapInSequence: true,
});
-
-export const PoppingWordCaptions = PoppingWordCaptionsLayer;
diff --git a/packages/docs/elements/captions/rounded-captions/rounded-captions.tsx b/packages/docs/elements/captions/rounded-captions/rounded-captions.tsx
index 7f24061762..03028e550e 100644
--- a/packages/docs/elements/captions/rounded-captions/rounded-captions.tsx
+++ b/packages/docs/elements/captions/rounded-captions/rounded-captions.tsx
@@ -63,19 +63,24 @@ const {fontFamily, waitUntilDone} = loadFont('normal', {
subsets: ['latin'],
});
-const RoundedCaptionsContent: React.FC<{
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
- readonly fontLoaded: boolean;
- readonly width: number;
- readonly height: number;
-}> = ({
+const RoundedCaptionsContent: React.FC<RoundedCaptionsProps> = ({
captions,
- combineTokensWithinMilliseconds,
- fontLoaded,
- width,
- height,
+ combineTokensWithinMilliseconds: providedCombineTokensWithinMilliseconds,
+ height = defaultHeight,
+ style,
+ width = defaultWidth,
}) => {
+ const [fontLoaded, setFontLoaded] = useState(false);
+
+ useEffect(() => {
+ waitUntilDone()
+ .then(() => setFontLoaded(true))
+ .catch((error) => cancelRender(error));
+ }, []);
+
+ const combineTokensWithinMilliseconds =
+ providedCombineTokensWithinMilliseconds ??
+ defaultCombineTokensWithinMilliseconds;
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const pages = useMemo(
@@ -143,71 +148,6 @@ const RoundedCaptionsContent: React.FC<{
};
}, [fontLoaded, height, page, width]);
- if (!layout) {
- return null;
- }
-
- return (
- <div
- style={{
- position: 'relative',
- width: layout.boundingBox.width,
- height: layout.boundingBox.height,
- flexShrink: 0,
- }}
- >
- <svg
- viewBox={layout.boundingBox.viewBox}
- style={{
- position: 'absolute',
- left: 0,
- top: 0,
- width: layout.boundingBox.width,
- height: layout.boundingBox.height,
- overflow: 'visible',
- }}
- >
- <path fill="#ffffff" d={layout.d} />
- </svg>
- <div style={{position: 'relative'}}>
- {layout.lines.map((line, index) => (
- <div
- // eslint-disable-next-line react/no-array-index-key
- key={index}
- style={{
- color: '#000000',
- fontFamily,
- fontSize: layout.fontSize,
- fontWeight,
- lineHeight,
- paddingInline: horizontalPadding,
- textAlign: 'center',
- whiteSpace: 'pre',
- }}
- >
- {line}
- </div>
- ))}
- </div>
- </div>
- );
-};
-
-const RoundedCaptionsInner: React.FC<RoundedCaptionsProps> = ({
- captions,
- combineTokensWithinMilliseconds,
- height = defaultHeight,
- style,
- width = defaultWidth,
-}) => {
- const [fontLoaded, setFontLoaded] = useState(false);
-
- useEffect(() => {
- waitUntilDone()
- .then(() => setFontLoaded(true))
- .catch((error) => cancelRender(error));
- }, []);
-
return (
<div
style={{
@@ -220,22 +160,56 @@ const RoundedCaptionsInner: React.FC<RoundedCaptionsProps> = ({
...style,
}}
>
- <RoundedCaptionsContent
- captions={captions}
- combineTokensWithinMilliseconds={
- combineTokensWithinMilliseconds ??
- defaultCombineTokensWithinMilliseconds
- }
- fontLoaded={fontLoaded}
- width={width}
- height={height}
- />
+ {layout ? (
+ <div
+ style={{
+ position: 'relative',
+ width: layout.boundingBox.width,
+ height: layout.boundingBox.height,
+ flexShrink: 0,
+ }}
+ >
+ <svg
+ viewBox={layout.boundingBox.viewBox}
+ style={{
+ position: 'absolute',
+ left: 0,
+ top: 0,
+ width: layout.boundingBox.width,
+ height: layout.boundingBox.height,
+ overflow: 'visible',
+ }}
+ >
+ <path fill="#ffffff" d={layout.d} />
+ </svg>
+ <div style={{position: 'relative'}}>
+ {layout.lines.map((line, index) => (
+ <div
+ // eslint-disable-next-line react/no-array-index-key
+ key={index}
+ style={{
+ color: '#000000',
+ fontFamily,
+ fontSize: layout.fontSize,
+ fontWeight,
+ lineHeight,
+ paddingInline: horizontalPadding,
+ textAlign: 'center',
+ whiteSpace: 'pre',
+ }}
+ >
+ {line}
+ </div>
+ ))}
+ </div>
+ </div>
+ ) : null}
</div>
);
};
export const RoundedCaptions = Interactive.withSchema({
- Component: RoundedCaptionsInner,
+ Component: RoundedCaptionsContent,
componentName: '<RoundedCaptions>',
schema: roundedCaptionsSchema,
wrapInSequence: true,
diff --git a/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx b/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx
index e35c09a21d..c68e3e35e4 100644
--- a/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx
+++ b/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx
@@ -184,47 +184,7 @@ const CaptionPage: React.FC<{
);
};
-const WordHighlightCaptionsContent: React.FC<{
- readonly captionAreaWidth: number | null;
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
- readonly fontLoaded: boolean;
-}> = ({
- captionAreaWidth,
- captions,
- combineTokensWithinMilliseconds,
- fontLoaded,
-}) => {
- const frame = useCurrentFrame();
- const {fps} = useVideoConfig();
- const pages = useMemo(
- () =>
- createTikTokStyleCaptions({
- captions,
- combineTokensWithinMilliseconds,
- }).pages,
- [captions, combineTokensWithinMilliseconds],
- );
- const currentTimeMs = (frame / fps) * 1000;
- const activePageIndex = getActivePageIndex(pages, currentTimeMs);
- const page = pages[activePageIndex];
-
- if (!fontLoaded || !page) {
- return null;
- }
-
- return (
- <CaptionPage
- key={`${activePageIndex}-${page.startMs}`}
- captionAreaWidth={captionAreaWidth}
- currentTimeMs={currentTimeMs}
- page={page}
- pageIndex={activePageIndex}
- />
- );
-};
-
-const WordHighlightCaptionsInner: React.FC<WordHighlightCaptionsProps> = ({
+const WordHighlightCaptionsContent: React.FC<WordHighlightCaptionsProps> = ({
captions,
combineTokensWithinMilliseconds = defaultCombineTokensWithinMilliseconds,
height = defaultHeight,
@@ -243,6 +203,20 @@ const WordHighlightCaptionsInner: React.FC<WordHighlightCaptionsProps> = ({
});
}, []);
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const pages = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds,
+ }).pages,
+ [captions, combineTokensWithinMilliseconds],
+ );
+ const currentTimeMs = (frame / fps) * 1000;
+ const activePageIndex = getActivePageIndex(pages, currentTimeMs);
+ const page = pages[activePageIndex];
+
return (
<div
style={{
@@ -252,21 +226,22 @@ const WordHighlightCaptionsInner: React.FC<WordHighlightCaptionsProps> = ({
...style,
}}
>
- <WordHighlightCaptionsContent
- captionAreaWidth={width ?? null}
- captions={captions}
- combineTokensWithinMilliseconds={combineTokensWithinMilliseconds}
- fontLoaded={fontLoaded}
- />
+ {fontLoaded && page ? (
+ <CaptionPage
+ key={`${activePageIndex}-${page.startMs}`}
+ captionAreaWidth={width ?? null}
+ currentTimeMs={currentTimeMs}
+ page={page}
+ pageIndex={activePageIndex}
+ />
+ ) : null}
</div>
);
};
-const WordHighlightCaptionsLayer = Interactive.withSchema({
- Component: WordHighlightCaptionsInner,
+export const WordHighlightCaptions = Interactive.withSchema({
+ Component: WordHighlightCaptionsContent,
componentName: '<WordHighlightCaptions>',
schema: wordHighlightCaptionsSchema,
wrapInSequence: true,
});
-
-export const WordHighlightCaptions = WordHighlightCaptionsLayer;
diff --git a/packages/docs/elements/maps/map-flyover/a-to-b-map-flyover.tsx b/packages/docs/elements/maps/map-flyover/a-to-b-map-flyover.tsx
index cb52373081..d718deb21d 100644
--- a/packages/docs/elements/maps/map-flyover/a-to-b-map-flyover.tsx
+++ b/packages/docs/elements/maps/map-flyover/a-to-b-map-flyover.tsx
@@ -271,21 +271,13 @@ const projectFlyoverRoute = (
};
};
-const MapFlyoverContent: React.FC<{
- readonly destination: readonly [number, number];
- readonly destinationLabel: string;
- readonly lineWidth: number;
- readonly origin: readonly [number, number];
- readonly originLabel: string;
- readonly routeColor: string;
- readonly style: React.CSSProperties | null;
-}> = ({
- destination,
- destinationLabel,
- lineWidth,
- origin,
- originLabel,
- routeColor,
+const MapFlyoverContent: React.FC<MapFlyoverLayerProps> = ({
+ destination = [139.6917, 35.6895],
+ destinationLabel = 'Tokyo',
+ lineWidth = 24,
+ origin = [-0.1276, 51.5072],
+ originLabel = 'London',
+ routeColor = '#ff5c4d',
style,
}) => {
const frame = useCurrentFrame();
@@ -598,30 +590,8 @@ const MapFlyoverContent: React.FC<{
);
};
-const MapFlyoverLayerInner: React.FC<MapFlyoverLayerProps> = ({
- destination = [139.6917, 35.6895],
- destinationLabel = 'Tokyo',
- lineWidth = 24,
- origin = [-0.1276, 51.5072],
- originLabel = 'London',
- routeColor = '#ff5c4d',
- style,
-}) => {
- return (
- <MapFlyoverContent
- destination={destination}
- destinationLabel={destinationLabel}
- lineWidth={lineWidth}
- origin={origin}
- originLabel={originLabel}
- routeColor={routeColor}
- style={style ?? null}
- />
- );
-};
-
export const MapFlyover = Interactive.withSchema({
- Component: MapFlyoverLayerInner,
+ Component: MapFlyoverContent,
componentName: '<MapFlyover>',
defaultSequenceName: 'A-to-B Map Flyover',
schema: mapFlyoverSchema,
diff --git a/packages/docs/elements/maps/watercolor-map/watercolor-map.tsx b/packages/docs/elements/maps/watercolor-map/watercolor-map.tsx
index 1e1ebb29ad..0ffd5f082c 100644
--- a/packages/docs/elements/maps/watercolor-map/watercolor-map.tsx
+++ b/packages/docs/elements/maps/watercolor-map/watercolor-map.tsx
@@ -158,21 +158,13 @@ const getTiles = ({
return tiles;
};
-const WatercolorMapContent: React.FC<{
- readonly destination: Coordinates;
- readonly destinationLabel: string;
- readonly origin: Coordinates;
- readonly originLabel: string;
- readonly routeColor: string;
- readonly routeWidth: number;
- readonly style: React.CSSProperties | undefined;
-}> = ({
- destination,
- destinationLabel,
- origin,
- originLabel,
- routeColor,
- routeWidth,
+const WatercolorMapContent: React.FC<WatercolorMapProps> = ({
+ destination = [8.5417, 47.3769],
+ destinationLabel = 'Zurich',
+ origin = [-118.2437, 34.0522],
+ originLabel = 'Los Angeles',
+ routeColor = '#ff0041',
+ routeWidth = 18,
style,
}) => {
const frame = useCurrentFrame();
@@ -397,30 +389,8 @@ const WatercolorMapContent: React.FC<{
);
};
-const WatercolorMapInner: React.FC<WatercolorMapProps> = ({
- destination = [8.5417, 47.3769],
- destinationLabel = 'Zurich',
- origin = [-118.2437, 34.0522],
- originLabel = 'Los Angeles',
- routeColor = '#ff0041',
- routeWidth = 18,
- style,
-}) => {
- return (
- <WatercolorMapContent
- destination={destination}
- destinationLabel={destinationLabel}
- origin={origin}
- originLabel={originLabel}
- routeColor={routeColor}
- routeWidth={routeWidth}
- style={style}
- />
- );
-};
-
export const WatercolorMap = Interactive.withSchema({
- Component: WatercolorMapInner,
+ Component: WatercolorMapContent,
componentName: '<WatercolorMap>',
defaultSequenceName: 'Watercolor map',
schema: watercolorMapSchema,
diff --git a/packages/example/src/mirrored-spectrum.element.tsx b/packages/example/src/mirrored-spectrum.element.tsx
index 1e974a7513..853d870f4e 100644
--- a/packages/example/src/mirrored-spectrum.element.tsx
+++ b/packages/example/src/mirrored-spectrum.element.tsx
@@ -51,13 +51,13 @@ const mirroredAudioSpectrumSchema = {
...Interactive.transformSchema,
} as const satisfies InteractivitySchema;
-const MirroredAudioSpectrumContent: React.FC<{
- readonly audioSrc: string;
- readonly barColor: string;
- readonly numberOfBars: number;
- readonly sensitivity: number;
- readonly style: MirroredAudioSpectrumProps['style'];
-}> = ({audioSrc, barColor, numberOfBars, sensitivity, style}) => {
+const MirroredAudioSpectrumContent: React.FC<MirroredAudioSpectrumProps> = ({
+ audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
+ barColor = '#0b84f3',
+ numberOfBars = 65,
+ sensitivity = 1.5,
+ style,
+}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const {audioData, dataOffsetInSeconds} = useWindowedAudioData({
@@ -120,26 +120,8 @@ const MirroredAudioSpectrumContent: React.FC<{
);
};
-const MirroredAudioSpectrumInner: React.FC<MirroredAudioSpectrumProps> = ({
- audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
- barColor = '#0b84f3',
- numberOfBars = 65,
- sensitivity = 1.5,
- style,
-}) => {
- return (
- <MirroredAudioSpectrumContent
- audioSrc={audioSrc}
- barColor={barColor}
- numberOfBars={numberOfBars}
- sensitivity={sensitivity}
- style={style}
- />
- );
-};
-
export const MirroredAudioSpectrum = Interactive.withSchema({
- Component: MirroredAudioSpectrumInner,
+ Component: MirroredAudioSpectrumContent,
componentName: '<MirroredAudioSpectrum>',
defaultSequenceName: 'Mirrored audio spectrum',
schema: mirroredAudioSpectrumSchema,
diff --git a/packages/example/src/moving-pill-captions.element.tsx b/packages/example/src/moving-pill-captions.element.tsx
index 6d1a35e326..8f6bbb100c 100644
--- a/packages/example/src/moving-pill-captions.element.tsx
+++ b/packages/example/src/moving-pill-captions.element.tsx
@@ -331,48 +331,7 @@ const CaptionPage: React.FC<{
);
};
-const MovingPillCaptionsContent: React.FC<{
- readonly captionAreaWidth: number | null;
- readonly captions: Caption[];
- readonly combineTokensWithinMilliseconds: number;
- readonly fontLoaded: boolean;
-}> = ({
- captionAreaWidth,
- captions,
- combineTokensWithinMilliseconds,
- fontLoaded,
-}) => {
- const frame = useCurrentFrame();
- const {fps} = useVideoConfig();
- const pages = useMemo(
- () =>
- createTikTokStyleCaptions({
- captions,
- combineTokensWithinMilliseconds,
- }).pages,
- [captions, combineTokensWithinMilliseconds],
- );
- const currentTimeMs = frameToMilliseconds(frame, fps);
- const activePageIndex = getActivePageIndex(pages, currentTimeMs);
- const page = pages[activePageIndex];
-
- if (!fontLoaded || !page) {
- return null;
- }
-
- return (
- <CaptionPage
- key={`${activePageIndex}-${page.startMs}`}
- captionAreaWidth={captionAreaWidth}
- currentTimeMs={currentTimeMs}
- fps={fps}
- page={page}
- pageIndex={activePageIndex}
- />
- );
-};
-
-const MovingPillCaptionsInner: React.FC<MovingPillCaptionsProps> = ({
+const MovingPillCaptionsContent: React.FC<MovingPillCaptionsProps> = ({
captions,
combineTokensWithinMilliseconds = defaultCombineTokensWithinMilliseconds,
height = defaultHeight,
@@ -391,6 +350,20 @@ const MovingPillCaptionsInner: React.FC<MovingPillCaptionsProps> = ({
});
}, []);
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const pages = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds,
+ }).pages,
+ [captions, combineTokensWithinMilliseconds],
+ );
+ const currentTimeMs = frameToMilliseconds(frame, fps);
+ const activePageIndex = getActivePageIndex(pages, currentTimeMs);
+ const page = pages[activePageIndex];
+
return (
<div
style={{
@@ -400,21 +373,23 @@ const MovingPillCaptionsInner: React.FC<MovingPillCaptionsProps> = ({
...style,
}}
>
- <MovingPillCaptionsContent
- captionAreaWidth={width ?? null}
- captions={captions}
- combineTokensWithinMilliseconds={combineTokensWithinMilliseconds}
- fontLoaded={fontLoaded}
- />
+ {fontLoaded && page ? (
+ <CaptionPage
+ key={`${activePageIndex}-${page.startMs}`}
+ captionAreaWidth={width ?? null}
+ currentTimeMs={currentTimeMs}
+ fps={fps}
+ page={page}
+ pageIndex={activePageIndex}
+ />
+ ) : null}
</div>
);
};
-const MovingPillCaptionsLayer = Interactive.withSchema({
- Component: MovingPillCaptionsInner,
+export const MovingPillCaptions = Interactive.withSchema({
+ Component: MovingPillCaptionsContent,
componentName: '<MovingPillCaptions>',
schema: movingPillCaptionsSchema,
wrapInSequence: true,
});
-
-export const MovingPillCaptions = MovingPillCaptionsLayer;
diff --git a/packages/example/src/oscilloscope.element.tsx b/packages/example/src/oscilloscope.element.tsx
index a65487622f..eb574c6535 100644
--- a/packages/example/src/oscilloscope.element.tsx
+++ b/packages/example/src/oscilloscope.element.tsx
@@ -64,14 +64,14 @@ const audioOscilloscopeSchema = {
...Interactive.transformSchema,
} as const satisfies InteractivitySchema;
-const AudioOscilloscopeContent: React.FC<{
- readonly amplitude: number;
- readonly audioSrc: string;
- readonly lineColor: string;
- readonly lineWidth: number;
- readonly style: AudioOscilloscopeProps['style'];
- readonly windowInSeconds: number;
-}> = ({amplitude, audioSrc, lineColor, lineWidth, style, windowInSeconds}) => {
+const AudioOscilloscopeContent: React.FC<AudioOscilloscopeProps> = ({
+ amplitude = 2,
+ audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
+ lineColor = '#55e6ff',
+ lineWidth = 6,
+ style,
+ windowInSeconds = 0.35,
+}) => {
const frame = useCurrentFrame();
const {fps} = useVideoConfig();
const {audioData, dataOffsetInSeconds} = useWindowedAudioData({
@@ -136,28 +136,8 @@ const AudioOscilloscopeContent: React.FC<{
);
};
-const AudioOscilloscopeInner: React.FC<AudioOscilloscopeProps> = ({
- amplitude = 2,
- audioSrc = 'https://remotion.media/elements/remotion-made-this-picture-move.mp3',
- lineColor = '#55e6ff',
- lineWidth = 6,
- style,
- windowInSeconds = 0.35,
-}) => {
- return (
- <AudioOscilloscopeContent
- amplitude={amplitude}
- audioSrc={audioSrc}
- lineColor={lineColor}
- lineWidth={lineWidth}
- style={style}
- windowInSeconds={windowInSeconds}
- />
- );
-};
-
export const AudioOscilloscope = Interactive.withSchema({
- Component: AudioOscilloscopeInner,
+ Component: AudioOscilloscopeContent,
componentName: '<AudioOscilloscope>',
defaultSequenceName: 'Audio oscilloscope',
schema: audioOscilloscopeSchema,
diff --git a/packages/maptiler/src/MapViewport.tsx b/packages/maptiler/src/MapViewport.tsx
index dc9e28146f..3e36531d30 100644
--- a/packages/maptiler/src/MapViewport.tsx
+++ b/packages/maptiler/src/MapViewport.tsx
@@ -1,17 +1,14 @@
-import {Map as MapTilerMap, MapStyle, type MapOptions} from '@maptiler/sdk';
-import type {ComponentType, CSSProperties, FC, ReactNode} from 'react';
+import {MapStyle, Map as MapTilerMap, type MapOptions} from '@maptiler/sdk';
import '@maptiler/sdk/style.css';
+import type {ComponentType, CSSProperties, FC, ReactNode} from 'react';
import {useEffect, useMemo, useRef, useState} from 'react';
import {
Interactive,
- Freeze,
- Sequence,
- Internals,
+ useDelayRender,
type InteractiveBaseProps,
type InteractivePremountProps,
type InteractivitySchema,
type SequenceControls,
- useDelayRender,
} from 'remotion';
import {MapTilerContext} from './MapTilerContext';
@@ -84,6 +81,8 @@ const stripStyleLayers = ({
};
const mapViewportSchema = {
+ // Keep the existing inspector field order. Interactive.withSchema() adds
+ // these fields again without changing their insertion position.
...Interactive.baseSchema,
...Interactive.premountSchema,
centerLongitude: {
@@ -207,13 +206,16 @@ const MissingApiKey = () => {
);
};
-const MapViewportContent: FC<
- MapViewportProps & {
- readonly premountingStyle: CSSProperties | null;
- }
-> = ({
+type MapViewportContentProps = Omit<
+ MapViewportProps,
+ keyof InteractiveBaseProps | keyof InteractivePremountProps | 'controls'
+> & {
+ readonly style?: CSSProperties;
+};
+
+const MapViewportContent: FC<MapViewportContentProps> = ({
apiKey,
- premountingStyle,
+ style,
backgroundColor = '#dfe7e2',
bearing = 0,
centerLatitude = 0,
@@ -500,7 +502,7 @@ const MapViewportContent: FC<
inset: 0,
overflow: 'hidden',
position: 'absolute',
- ...premountingStyle,
+ ...style,
}}
>
{apiKey ? (
@@ -523,75 +525,10 @@ const MapViewportContent: FC<
);
};
-const MapViewportInner: FC<MapViewportProps> = ({
- durationInFrames,
- from,
- trimBefore,
- playbackRate,
- loop,
- freeze,
- hidden,
- name,
- showInTimeline,
- controls,
- premountFor,
- postmountFor,
- styleWhilePremounted,
- styleWhilePostmounted,
- ...props
-}) => {
- const {
- effectivePremountFor,
- effectivePostmountFor,
- freezeFrame,
- isPremountingOrPostmounting,
- premountingActive,
- postmountingActive,
- premountingStyle,
- } = Internals.usePremounting({
- from: from ?? 0,
- durationInFrames: Internals.resolveSequenceDuration({
- durationInFrames,
- playbackRate,
- loop,
- }),
- premountFor: premountFor ?? null,
- postmountFor: postmountFor ?? null,
- style: null,
- styleWhilePremounted: styleWhilePremounted ?? null,
- styleWhilePostmounted: styleWhilePostmounted ?? null,
- hideWhilePremounted: 'opacity',
- });
-
- return (
- <Freeze frame={freezeFrame} active={isPremountingOrPostmounting}>
- <Sequence
- layout="none"
- durationInFrames={durationInFrames}
- from={from}
- trimBefore={trimBefore}
- playbackRate={playbackRate}
- loop={loop}
- freeze={freeze}
- hidden={hidden}
- showInTimeline={showInTimeline}
- controls={controls}
- name={name ?? '<MapViewport>'}
- _remotionInternalPremountDisplay={effectivePremountFor || null}
- _remotionInternalPostmountDisplay={effectivePostmountFor || null}
- _remotionInternalIsPremounting={premountingActive}
- _remotionInternalIsPostmounting={postmountingActive}
- >
- <MapViewportContent {...props} premountingStyle={premountingStyle} />
- </Sequence>
- </Freeze>
- );
-};
-
export const MapViewport: ComponentType<MapViewportProps> =
Interactive.withSchema({
- Component: MapViewportInner,
+ Component: MapViewportContent,
componentName: '<MapViewport>',
schema: mapViewportSchema,
- supportsEffects: false,
+ wrapInSequence: true,
});