Skip to content

🎥 Make videos programmatically with React

Make page turn demos editable in Studio

Jonny Burgera4334ee1a8c9
diff --git a/packages/docs/components/effects/effects-page-turn-preview.tsx b/packages/docs/components/effects/effects-page-turn-preview.tsx
index 847d122d5c..a63eaaf2ea 100644
--- a/packages/docs/components/effects/effects-page-turn-preview.tsx
+++ b/packages/docs/components/effects/effects-page-turn-preview.tsx
@@ -1,8 +1,4 @@
-import {
- pageTurn,
- type PageTurnParams,
- type PageTurnRender,
-} from '@remotion/effects/page-turn';
+import {pageTurn, type PageTurnRender} from '@remotion/effects/page-turn';
import {Video} from '@remotion/media';
import React from 'react';
import {
@@ -10,6 +6,7 @@ import {
CanvasImage,
Easing,
HtmlInCanvas,
+ Interactive,
interpolate,
useCurrentFrame,
} from 'remotion';
@@ -38,88 +35,148 @@ export const EffectsPageTurnPreview: React.FC<{
);
};
-export const PageTurnScene: React.FC = () => {
+const PageTurnSceneInner: React.FC = () => {
const frame = useCurrentFrame();
- const progress = interpolate(frame, [20, 145], [0, 1], {
- easing: Easing.inOut(Easing.cubic),
- extrapolateLeft: 'clamp',
- extrapolateRight: 'clamp',
- });
- const params: PageTurnParams = {
- foldPosition: [interpolate(progress, [0, 1], [1.4, -0.5]), 0.5],
- foldDirection: -75,
- foldRadius: 85,
- paperColor: '#f7f3eb',
- backPageOpacity: 0.12,
- };
return (
- <AbsoluteFill
- style={{
- backgroundColor: '#182033',
- color: '#f7f3eb',
- fontFamily: 'Arial, Helvetica, sans-serif',
- }}
- >
- <AbsoluteFill style={{justifyContent: 'center', padding: 90}}>
- <div style={{fontSize: 22, letterSpacing: 5, marginBottom: 32}}>
+ <>
+ <AbsoluteFill
+ showInTimeline={false}
+ style={{justifyContent: 'center', padding: 90}}
+ >
+ <Interactive.Div
+ name="Next chapter label"
+ style={{
+ fontSize: 22,
+ letterSpacing: 5,
+ marginBottom: 32,
+ color: '#f7f3eb',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ }}
+ >
CHAPTER TWO
- </div>
- <div style={{fontSize: 112, fontWeight: 700, lineHeight: 0.95}}>
- A fresh
- <br />
- perspective.
- </div>
+ </Interactive.Div>
+ <Interactive.Div
+ name="Next chapter title"
+ style={{
+ fontSize: 112,
+ fontWeight: 700,
+ lineHeight: 0.95,
+ whiteSpace: 'pre-line',
+ color: '#f7f3eb',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ }}
+ >
+ {'A fresh\nperspective.'}
+ </Interactive.Div>
</AbsoluteFill>
- <HtmlInCanvas width={1280} height={720} effects={[pageTurn(params)]}>
+ <HtmlInCanvas
+ name="Turning page"
+ width={1280}
+ height={720}
+ effects={[
+ pageTurn({
+ foldPosition: interpolate(
+ frame,
+ [20, 82.5, 145],
+ [
+ [1.4, 0.5],
+ [0.45, 0.5],
+ [-0.5, 0.5],
+ ],
+ {
+ easing: [Easing.cubic, Easing.out(Easing.cubic)],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ },
+ ),
+ foldDirection: -75,
+ foldRadius: 85,
+ paperColor: '#f7f3eb',
+ backPageOpacity: 0.12,
+ }),
+ ]}
+ >
<AbsoluteFill
- style={{backgroundColor: '#f7f3eb', color: '#182033', padding: 90}}
+ showInTimeline={false}
+ style={{backgroundColor: '#f7f3eb', padding: 90}}
>
- <div
- style={{
- display: 'flex',
- justifyContent: 'space-between',
- fontSize: 22,
- letterSpacing: 4,
- }}
- >
- <span>CHAPTER ONE</span>
- <span>01 / 02</span>
+ <div style={{display: 'flex', justifyContent: 'space-between'}}>
+ <Interactive.Span
+ name="Front chapter label"
+ style={{
+ fontSize: 22,
+ letterSpacing: 4,
+ color: '#182033',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ }}
+ >
+ CHAPTER ONE
+ </Interactive.Span>
+ <Interactive.Span
+ name="Page number"
+ style={{
+ fontSize: 22,
+ letterSpacing: 4,
+ color: '#182033',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ }}
+ >
+ 01 / 02
+ </Interactive.Span>
</div>
- <div
+ <Interactive.Div
+ name="Front page title"
style={{
fontSize: 130,
fontWeight: 700,
lineHeight: 0.9,
letterSpacing: -6,
marginTop: 95,
+ whiteSpace: 'pre-line',
+ color: '#182033',
+ fontFamily: 'Arial, Helvetica, sans-serif',
}}
>
- Turn
- <br />
- the page.
- </div>
- <div
+ {'Turn\nthe page.'}
+ </Interactive.Div>
+ <Interactive.Div
+ name="Front page footer"
style={{
marginTop: 'auto',
borderTop: '2px solid #182033',
paddingTop: 24,
fontSize: 24,
+ color: '#182033',
+ fontFamily: 'Arial, Helvetica, sans-serif',
}}
>
Every ending is a new beginning.
- </div>
+ </Interactive.Div>
</AbsoluteFill>
</HtmlInCanvas>
- </AbsoluteFill>
+ </>
);
};
+export const PageTurnScene = Interactive.create({
+ Component: PageTurnSceneInner,
+ componentName: '<PageTurnScene>',
+ layout: 'absolute-fill',
+ schema: {...Interactive.backgroundSchema},
+});
+
export const PageTurnDemo: React.FC = () => {
const branch = useHtmlInCanvasDocsDemoBranch('webgpu');
if (branch === 'pending') return null;
- if (branch === 'live') return <PageTurnScene />;
+ if (branch === 'live') {
+ return (
+ <PageTurnScene name="Page turn" style={{backgroundColor: '#182033'}} />
+ );
+ }
+
return (
<Video
+ name="Page turn preview"
muted
src="https://remotion.media/page-turn-demo-1025fe4ae350.mp4"
style={{width: '100%', height: '100%'}}
diff --git a/packages/docs/docs/effects/page-turn.mdx b/packages/docs/docs/effects/page-turn.mdx
index 7ab3a0fdb8..625f87b851 100644
--- a/packages/docs/docs/effects/page-turn.mdx
+++ b/packages/docs/docs/effects/page-turn.mdx
@@ -27,10 +27,6 @@ import {CanvasImage, interpolate, useCurrentFrame} from 'remotion';
export const MyComp: React.FC = () => {
const frame = useCurrentFrame();
- const x = interpolate(frame, [0, 90], [1.4, -0.5], {
- extrapolateLeft: 'clamp',
- extrapolateRight: 'clamp',
- });
return (
<CanvasImage
@@ -40,7 +36,13 @@ export const MyComp: React.FC = () => {
fit="cover"
effects={[
pageTurn({
- foldPosition: [x, 0.5],
+ foldPosition: interpolate(frame, [0, 90], [
+ [1.4, 0.5],
+ [-0.5, 0.5],
+ ], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }),
foldDirection: -75,
foldRadius: 85,
}),
diff --git a/packages/docs/elements/commerce/peel/peel.tsx b/packages/docs/elements/commerce/peel/peel.tsx
index 46ea581a55..a48b2831e9 100644
--- a/packages/docs/elements/commerce/peel/peel.tsx
+++ b/packages/docs/elements/commerce/peel/peel.tsx
@@ -20,14 +20,24 @@ const PeelInner: React.FC = () => {
effects={[
scale({scale: 0.75}),
pageTurn({
- foldPosition: [
- interpolate(frame, [6, durationInFrames - 9], [1.25, -0.45], {
- easing: Easing.inOut(Easing.quad),
+ foldPosition: interpolate(
+ frame,
+ [
+ durationInFrames * 0.1,
+ durationInFrames * 0.475,
+ durationInFrames * 0.85,
+ ],
+ [
+ [1.25, 0.5],
+ [0.4, 0.5],
+ [-0.45, 0.5],
+ ],
+ {
+ easing: [Easing.quad, Easing.out(Easing.quad)],
extrapolateLeft: 'clamp',
extrapolateRight: 'clamp',
- }),
- 0.5,
- ],
+ },
+ ),
foldDirection: -75,
foldRadius: 70,
paperColor: '#ffffff',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index bf12fbf4a8..198713e36d 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -254,6 +254,7 @@ export const RemotionRoot: React.FC = () => {
<Composition
id="page-turn-demo"
component={PageTurnScene}
+ defaultProps={{style: {backgroundColor: '#182033'}}}
width={1280}
height={720}
fps={30}