Skip to content

🎥 Make videos programmatically with React

Merge pull request #11253 from remotion-dev/elements/layouts

Igor Samokhovets684a661f0773
diff --git a/packages/docs/elements/layouts/index.mdx b/packages/docs/elements/layouts/index.mdx
new file mode 100644
index 0000000000..13a0fd59c9
--- /dev/null
+++ b/packages/docs/elements/layouts/index.mdx
@@ -0,0 +1,10 @@
+---
+title: Layouts
+description: Animated layouts for arranging content in Remotion videos.
+---
+
+import {ElementLibrary} from '@site/src/components/Elements/ElementLibrary';
+
+# Layouts
+
+<ElementLibrary category="layouts" />
diff --git a/packages/docs/elements/layouts/picture-in-picture-transition/index.mdx b/packages/docs/elements/layouts/picture-in-picture-transition/index.mdx
new file mode 100644
index 0000000000..e066c0b754
--- /dev/null
+++ b/packages/docs/elements/layouts/picture-in-picture-transition/index.mdx
@@ -0,0 +1,12 @@
+---
+title: Picture in Picture Transition
+description: Animates an element from being fullscreen to being displayed in a box.
+image: https://remotion.media/elements/layouts-picture-in-picture-transition-preview.png
+---
+
+import {ElementPage} from '@site/src/components/Elements/ElementPage';
+import {getElementDefinition} from '@site/src/components/Elements/element-utils';
+
+# Picture in Picture Transition
+
+<ElementPage definition={getElementDefinition('layouts/picture-in-picture-transition')} sourceFile="./picture-in-picture-transition.tsx" />
diff --git a/packages/docs/elements/layouts/picture-in-picture-transition/picture-in-picture-transition.tsx b/packages/docs/elements/layouts/picture-in-picture-transition/picture-in-picture-transition.tsx
new file mode 100644
index 0000000000..fb9d14ae72
--- /dev/null
+++ b/packages/docs/elements/layouts/picture-in-picture-transition/picture-in-picture-transition.tsx
@@ -0,0 +1,177 @@
+import React from 'react';
+import {
+ AbsoluteFill,
+ Easing,
+ Img,
+ Interactive,
+ interpolate,
+ useCurrentFrame,
+} from 'remotion';
+
+export const PictureInPictureTransition: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill style={{overflow: 'hidden'}}>
+ <Interactive.Div
+ name="Scene B"
+ style={{
+ alignItems: 'center',
+ color: '#ffffff',
+ display: 'flex',
+ fontFamily: 'sans-serif',
+ fontSize: 240,
+ fontWeight: 900,
+ inset: 0,
+ justifyContent: 'center',
+ position: 'absolute',
+ textShadow: '0 4px 30px rgba(0, 0, 0, 0.55)',
+ }}
+ >
+ <Img
+ alt=""
+ name="Scene B background"
+ src="https://remotion.media/transition-bg-pink.jpg"
+ style={{
+ height: '100%',
+ objectFit: 'cover',
+ position: 'absolute',
+ width: '100%',
+ }}
+ />
+ <div style={{position: 'relative'}}>B</div>
+ </Interactive.Div>
+
+ <Interactive.Div
+ cropBottom={interpolate(frame, [15, 50], [0, 0.06], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ })}
+ cropLeft={interpolate(frame, [15, 50], [0, 0.302], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ })}
+ cropRight={interpolate(frame, [15, 50], [0, 0.302], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ })}
+ cropTop={interpolate(frame, [15, 50], [0, 0.06], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ })}
+ name="Scene A"
+ style={{
+ alignItems: 'center',
+ borderRadius: interpolate(frame, [15, 50], [0, 48], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }),
+ color: '#ffffff',
+ display: 'flex',
+ fontFamily: 'sans-serif',
+ fontSize: 240,
+ fontWeight: 900,
+ height: '100%',
+ justifyContent: 'center',
+ overflow: 'hidden',
+ position: 'absolute',
+ scale: interpolate(frame, [15, 50], [1, 0.38], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }),
+ textShadow: '0 4px 30px rgba(0, 0, 0, 0.55)',
+ transformOrigin: 'top left',
+ translate: interpolate(frame, [15, 50], ['0px 0px', '1363px 23px'], {
+ easing: [
+ Easing.spring({
+ damping: 200,
+ mass: 1,
+ stiffness: 100,
+ allowTail: true,
+ durationRestThreshold: 0.02,
+ overshootClamping: false,
+ }),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }),
+ width: '100%',
+ willChange: 'transform',
+ }}
+ >
+ <Img
+ alt=""
+ name="Scene A background"
+ src="https://remotion.media/transition-bg-blue.jpg"
+ style={{
+ height: '100%',
+ objectFit: 'cover',
+ position: 'absolute',
+ width: '100%',
+ }}
+ />
+ <div style={{position: 'relative'}}>A</div>
+ </Interactive.Div>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docs/elements/layouts/slide-to-split-screen/index.mdx b/packages/docs/elements/layouts/slide-to-split-screen/index.mdx
new file mode 100644
index 0000000000..207aafa935
--- /dev/null
+++ b/packages/docs/elements/layouts/slide-to-split-screen/index.mdx
@@ -0,0 +1,12 @@
+---
+title: Slide to Split Screen
+description: A fullscreen scene that opens into a 60/40 split-screen layout.
+image: https://remotion.media/elements/layouts-slide-to-split-screen-preview.png
+---
+
+import {ElementPage} from '@site/src/components/Elements/ElementPage';
+import {getElementDefinition} from '@site/src/components/Elements/element-utils';
+
+# Slide to Split Screen
+
+<ElementPage definition={getElementDefinition('layouts/slide-to-split-screen')} sourceFile="./slide-to-split-screen.tsx" />
diff --git a/packages/docs/elements/layouts/slide-to-split-screen/slide-to-split-screen.tsx b/packages/docs/elements/layouts/slide-to-split-screen/slide-to-split-screen.tsx
new file mode 100644
index 0000000000..3d62f333df
--- /dev/null
+++ b/packages/docs/elements/layouts/slide-to-split-screen/slide-to-split-screen.tsx
@@ -0,0 +1,128 @@
+import React from 'react';
+import {
+ AbsoluteFill,
+ Easing,
+ Img,
+ Interactive,
+ interpolate,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+const DIVIDER_WIDTH = 15;
+
+export const SlideToSplitScreen: React.FC = () => {
+ const frame = useCurrentFrame();
+ const {height, width} = useVideoConfig();
+ const bPanelWidth = width * 0.4;
+ const aPanelWidth = width - bPanelWidth - DIVIDER_WIDTH;
+ const aShift = (width - aPanelWidth) / 2;
+ const splitProgress = interpolate(frame, [20, 52, 98, 130], [0, 1, 1, 0], {
+ easing: [
+ Easing.bezier(0.65, 0, 0.35, 1),
+ Easing.linear,
+ Easing.bezier(0.65, 0, 0.35, 1),
+ ],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+
+ return (
+ <AbsoluteFill
+ style={{
+ overflow: 'hidden',
+ }}
+ >
+ <div
+ style={{
+ height,
+ overflow: 'hidden',
+ position: 'absolute',
+ width: interpolate(splitProgress, [0, 1], [width, aPanelWidth]),
+ }}
+ >
+ <Interactive.Div
+ name="Scene A"
+ style={{
+ alignItems: 'center',
+ color: '#ffffff',
+ display: 'flex',
+ fontFamily: 'sans-serif',
+ fontSize: 240,
+ fontWeight: 900,
+ height,
+ justifyContent: 'center',
+ position: 'absolute',
+ textShadow: '0 4px 30px rgba(0, 0, 0, 0.55)',
+ translate: `${-aShift * splitProgress}px 0px`,
+ width,
+ willChange: 'transform',
+ }}
+ >
+ <Img
+ alt=""
+ name="Scene A background"
+ src="https://remotion.media/transition-bg-blue.jpg"
+ style={{
+ height: '100%',
+ objectFit: 'cover',
+ position: 'absolute',
+ width: '100%',
+ }}
+ />
+ <div style={{position: 'relative'}}>A</div>
+ </Interactive.Div>
+ </div>
+
+ <div
+ style={{
+ display: 'flex',
+ height,
+ position: 'absolute',
+ right: 0,
+ translate: `${(1 - splitProgress) * (bPanelWidth + DIVIDER_WIDTH)}px 0px`,
+ width: bPanelWidth + DIVIDER_WIDTH,
+ willChange: 'transform',
+ }}
+ >
+ <Interactive.Div
+ name="Divider"
+ style={{
+ backgroundColor: '#ffffff',
+ flex: `0 0 ${DIVIDER_WIDTH}px`,
+ height: '100%',
+ }}
+ />
+ <Interactive.Div
+ name="Scene B"
+ style={{
+ alignItems: 'center',
+ color: '#ffffff',
+ display: 'flex',
+ fontFamily: 'sans-serif',
+ fontSize: 240,
+ fontWeight: 900,
+ height,
+ justifyContent: 'center',
+ position: 'relative',
+ textShadow: '0 4px 30px rgba(0, 0, 0, 0.55)',
+ width: bPanelWidth,
+ }}
+ >
+ <Img
+ alt=""
+ name="Scene B background"
+ src="https://remotion.media/transition-bg-pink.jpg"
+ style={{
+ height: '100%',
+ objectFit: 'cover',
+ position: 'absolute',
+ width: '100%',
+ }}
+ />
+ <div style={{position: 'relative'}}>B</div>
+ </Interactive.Div>
+ </div>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.ts
index 689cd2faa8..97b199c19d 100644
--- a/packages/docs/src/components/Elements/element-definitions.ts
+++ b/packages/docs/src/components/Elements/element-definitions.ts
@@ -33,6 +33,8 @@ import {LineChart} from '../../../elements/data/line-chart/line-chart';
import {NumberCounter} from '../../../elements/data/number-counter/number-counter';
import {PieChart} from '../../../elements/data/pie-chart/pie-chart';
import {VerticalBarChart} from '../../../elements/data/vertical-bar-chart/vertical-bar-chart';
+import {PictureInPictureTransition} from '../../../elements/layouts/picture-in-picture-transition/picture-in-picture-transition';
+import {SlideToSplitScreen} from '../../../elements/layouts/slide-to-split-screen/slide-to-split-screen';
import {MapFlyover} from '../../../elements/maps/map-flyover/a-to-b-map-flyover';
import {WatercolorMap} from '../../../elements/maps/watercolor-map/watercolor-map';
import {LocationLowerThird} from '../../../elements/overlays/location-lower-third/location-lower-third';
@@ -650,6 +652,56 @@ const elementImplementations = [
installationMode: 'wrapped',
width: 1920,
},
+ {
+ slug: 'layouts/picture-in-picture-transition',
+ component: PictureInPictureTransition,
+ contributors: [],
+ description:
+ 'Animates an element from being fullscreen to being displayed in a box.',
+ dependencies: [],
+ durationInFrames: 150,
+ elementHeight: null,
+ elementWidth: null,
+ fps: 30,
+ height: 1080,
+ posterFrame: 75,
+ preview: {
+ previewLayout: 'composition',
+ posterUrl:
+ 'https://remotion.media/elements/layouts-picture-in-picture-transition-preview.png',
+ videoUrl:
+ 'https://remotion.media/elements/layouts-picture-in-picture-transition-preview.mp4',
+ },
+ safeArea: 0,
+ initialProps: null,
+ installationMode: 'wrapped',
+ width: 1920,
+ },
+ {
+ slug: 'layouts/slide-to-split-screen',
+ component: SlideToSplitScreen,
+ contributors: [],
+ description:
+ 'A fullscreen scene that opens into a 60/40 split-screen layout.',
+ dependencies: [],
+ durationInFrames: 150,
+ elementHeight: null,
+ elementWidth: null,
+ fps: 30,
+ height: 1080,
+ posterFrame: 75,
+ preview: {
+ previewLayout: 'composition',
+ posterUrl:
+ 'https://remotion.media/elements/layouts-slide-to-split-screen-preview.png',
+ videoUrl:
+ 'https://remotion.media/elements/layouts-slide-to-split-screen-preview.mp4',
+ },
+ safeArea: 0,
+ initialProps: null,
+ installationMode: 'wrapped',
+ width: 1920,
+ },
{
slug: 'maps/map-flyover',
component: MapFlyover,
diff --git a/packages/docs/src/components/Elements/element-registry.ts b/packages/docs/src/components/Elements/element-registry.ts
index 6557678695..ffcc937a8a 100644
--- a/packages/docs/src/components/Elements/element-registry.ts
+++ b/packages/docs/src/components/Elements/element-registry.ts
@@ -4,6 +4,7 @@ export const elementCategories = [
{category: 'captions', label: 'Captions'},
{category: 'data', label: 'Charts & Data'},
{category: 'commerce', label: 'Effects'},
+ {category: 'layouts', label: 'Layouts'},
{category: 'maps', label: 'Maps'},
{category: 'overlays', label: 'Overlays'},
{category: 'storytelling', label: 'Storytelling'},
@@ -67,7 +68,7 @@ export const elementRegistry = {
displayName: 'Word Highlight Captions',
},
'commerce/product-collection': {
- category: 'commerce',
+ category: 'layouts',
displayName: 'Rotating Cards',
},
'commerce/product-discount-callout': {
@@ -102,6 +103,14 @@ export const elementRegistry = {
category: 'data',
displayName: 'Vertical Bar Chart',
},
+ 'layouts/picture-in-picture-transition': {
+ category: 'layouts',
+ displayName: 'Picture in Picture Transition',
+ },
+ 'layouts/slide-to-split-screen': {
+ category: 'layouts',
+ displayName: 'Slide to Split Screen',
+ },
'maps/map-flyover': {
category: 'maps',
displayName: 'A-to-B Map Flyover',