🎥 Make videos programmatically with React
hide
Jonny Burger74860e97e365
diff --git a/packages/core/src/Clipper.tsx b/packages/core/src/Clipper.tsxindex 808855937e..b8fbfa5388 100644--- a/packages/core/src/Clipper.tsx+++ b/packages/core/src/Clipper.tsx@@ -9,17 +9,18 @@ export const Clipper: React.FC<height: number;x: number;y: number;+ hide?: boolean;}>-> = ({height, width, x, y, children}) => {+> = ({height, width, x, y, hide, children}) => {const context = useContext(CompositionManager);useEffect(() => {- context.setClipRegion({height, width, x, y});+ context.setClipRegion({height, hide: Boolean(hide), width, x, y});return () => {context.setClipRegion(null);};- }, [context, height, width, x, y]);+ }, [context, height, hide, width, x, y]);return <AbsoluteFill>{children}</AbsoluteFill>;};diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsxindex ddef936aef..54913a7767 100644--- a/packages/core/src/CompositionManager.tsx+++ b/packages/core/src/CompositionManager.tsx@@ -88,6 +88,7 @@ export type ClipRegion = {y: number;width: number;height: number;+ hide: boolean;};export type CompositionManagerContext = {diff --git a/packages/example/src/ReactSvg/index.tsx b/packages/example/src/ReactSvg/index.tsxindex 823c9e1871..d1b3584a2f 100644--- a/packages/example/src/ReactSvg/index.tsx+++ b/packages/example/src/ReactSvg/index.tsx@@ -1,5 +1,11 @@import React from 'react';-import {Easing, interpolate, useCurrentFrame, useVideoConfig} from 'remotion';+import {+ Clipper,+ Easing,+ interpolate,+ useCurrentFrame,+ useVideoConfig,+} from 'remotion';import {Arc} from './Arc';import {Atom} from './Atom';import {Black} from './Black';@@ -83,41 +89,51 @@ const ReactSvg: React.FC<{const scale = frame < 70 ? scaleIn : scaleOut;return (- <div style={{flex: 1, backgroundColor: transparent ? undefined : 'white'}}>+ <Clipper+ hide={frame < 150}+ x={0}+ y={0}+ width={videoConfig.width / 2}+ height={videoConfig.height}+ ><div- style={{- position: 'absolute',- width: videoConfig.width,- height: videoConfig.height,- transform: `scale(${scale})`,- }}+ style={{flex: 1, backgroundColor: transparent ? undefined : 'white'}}>- {transparent ? null : <DotGrid />}- <Arc- rotateProgress={rotationDevelopment}- progress={development}- rotation={30}- electronProgress={electronDevelopment}- electronOpacity={electronOpacity}- />- <Arc- rotateProgress={rotationDevelopment}- rotation={90}- progress={frame < rotateStart ? 0 : 1}- electronProgress={electronDevelopment * 1.2 + 0.33}- electronOpacity={electronOpacity}- />- <Arc- rotateProgress={rotationDevelopment}- rotation={-30}- progress={frame < rotateStart ? 0 : 1}- electronProgress={electronDevelopment + 0.66}- electronOpacity={electronOpacity}- />- <Atom scale={rotationDevelopment} />- {transparent ? null : <Black scale={scaleOutBlackDot} />}+ <div+ style={{+ position: 'absolute',+ width: videoConfig.width,+ height: videoConfig.height,+ transform: `scale(${scale})`,+ }}+ >+ {transparent ? null : <DotGrid />}+ <Arc+ rotateProgress={rotationDevelopment}+ progress={development}+ rotation={30}+ electronProgress={electronDevelopment}+ electronOpacity={electronOpacity}+ />+ <Arc+ rotateProgress={rotationDevelopment}+ rotation={90}+ progress={frame < rotateStart ? 0 : 1}+ electronProgress={electronDevelopment * 1.2 + 0.33}+ electronOpacity={electronOpacity}+ />+ <Arc+ rotateProgress={rotationDevelopment}+ rotation={-30}+ progress={frame < rotateStart ? 0 : 1}+ electronProgress={electronDevelopment + 0.66}+ electronOpacity={electronOpacity}+ />+ <Atom scale={rotationDevelopment} />+ {transparent ? null : <Black scale={scaleOutBlackDot} />}+ </div></div>- </div>+ </Clipper>);};diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.tsindex 763fcd7881..0dffeb63dc 100644--- a/packages/renderer/src/render-frames.ts+++ b/packages/renderer/src/render-frames.ts@@ -387,35 +387,39 @@ const innerRenderFrames = ({}));- await provideScreenshot({- page: freePage,- imageFormat,- quality,- options: {- frame,- output: clipRegion ? output : composedOutput,- },- height,- width,- clipRegion,- });+ if (!clipRegion?.hide) {+ await provideScreenshot({+ page: freePage,+ imageFormat,+ quality,+ options: {+ frame,+ output: clipRegion ? output : composedOutput,+ },+ height,+ width,+ clipRegion,+ });+ }if (clipRegion) {compose({height: composition.height,width: composition.width,layers: [- {- type: 'Image',- params: {- height: clipRegion.height,- width: clipRegion.width,- src: output,- x: clipRegion.x,- y: clipRegion.y,- },- },- ],+ clipRegion.hide+ ? null+ : {+ type: 'Image' as const,+ params: {+ height: clipRegion.height,+ width: clipRegion.width,+ src: output,+ x: clipRegion.x,+ y: clipRegion.y,+ },+ },+ ].filter(truthy),output: composedOutput,});}