🎥 Make videos programmatically with React
flip() transition
Jonny Burgerb76522f2ae26
diff --git a/packages/docs/components/TableOfContents/transitions/presentations.tsx b/packages/docs/components/TableOfContents/transitions/presentations.tsxindex 23a800a51e..89aaf0a010 100644--- a/packages/docs/components/TableOfContents/transitions/presentations.tsx+++ b/packages/docs/components/TableOfContents/transitions/presentations.tsx@@ -1,4 +1,5 @@import { fade } from "@remotion/transitions/fade";+import { flip } from "@remotion/transitions/flip";import { slide } from "@remotion/transitions/slide";import { wipe } from "@remotion/transitions/wipe";import React from "react";@@ -56,6 +57,17 @@ export const Presentations: React.FC = () => {</div></div></TOCItem>+ <TOCItem link="/docs/transitions/presentations/flip">+ <div style={row}>+ <PresentationPreview durationRestThreshold={0.001} effect={flip()} />+ <div style={{ flex: 1, marginLeft: 10 }}>+ <strong>+ <code>{"flip()"}</code>+ </strong>+ <div>Rotate the previous scene</div>+ </div>+ </div>+ </TOCItem></Grid>);};diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsxindex ee84dc27d1..34d1351ae7 100644--- a/packages/docs/components/demos/index.tsx+++ b/packages/docs/components/demos/index.tsx@@ -11,6 +11,7 @@ import {customTimingDemo,ellipseDemo,fadePresentationDemo,+ flipPresentationDemo,noiseDemo,opacityDemo,pieDemo,@@ -51,6 +52,7 @@ const demos: DemoType[] = [wipePresentationDemo,slidePresentationDemo,slidePresentationDemoLongThreshold,+ flipPresentationDemo,customPresentationDemo,customTimingDemo,];diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex e9020300a8..ba866bbd9d 100644--- a/packages/docs/components/demos/types.ts+++ b/packages/docs/components/demos/types.ts@@ -2,6 +2,7 @@ import {CustomTimingDemo,CustomTransitionDemo,FadeDemo,+ FlipDemo,SlideDemo,SlideDemoLongDurationRest,WipeDemo,@@ -507,6 +508,24 @@ export const slidePresentationDemo: DemoType = {},],};+export const flipPresentationDemo: DemoType = {+ comp: FlipDemo,+ compHeight: 280,+ compWidth: 540,+ durationInFrames: 60,+ fps: 30,+ id: "flip",+ autoPlay: true,+ options: [+ {+ type: "enum",+ name: "direction",+ default: "from-left",+ optional: "no",+ values: ["from-left", "from-bottom", "from-right", "from-top"],+ },+ ],+};export const slidePresentationDemoLongThreshold: DemoType = {comp: SlideDemoLongDurationRest,diff --git a/packages/docs/components/transitions/previews.tsx b/packages/docs/components/transitions/previews.tsxindex 082cbb8e9e..d49c1c5836 100644--- a/packages/docs/components/transitions/previews.tsx+++ b/packages/docs/components/transitions/previews.tsx@@ -6,6 +6,8 @@ import type {} from "@remotion/transitions";import { springTiming, TransitionSeries } from "@remotion/transitions";import { fade } from "@remotion/transitions/fade";+import type { FlipDirection } from "@remotion/transitions/flip";+import { flip } from "@remotion/transitions/flip";import type { SlideDirection } from "@remotion/transitions/slide";import { slide } from "@remotion/transitions/slide";import type { WipeDirection } from "@remotion/transitions/wipe";@@ -96,6 +98,17 @@ export const SlideDemo: React.FC<{);};+export const FlipDemo: React.FC<{+ direction: FlipDirection;+}> = ({ direction }) => {+ return (+ <SampleTransition+ effect={flip({ direction })}+ durationRestThreshold={0.001}+ />+ );+};+export const SlideDemoLongDurationRest: React.FC<{direction: SlideDirection;}> = ({ direction }) => {diff --git a/packages/docs/docs/transitions/presentations/flip.mdx b/packages/docs/docs/transitions/presentations/flip.mdxnew file mode 100644index 0000000000..ec22aebb1f--- /dev/null+++ b/packages/docs/docs/transitions/presentations/flip.mdx@@ -0,0 +1,74 @@+---+image: /generated/articles-docs-transitions-presentations-flip.png+crumb: "@remotion/transitions - Presentations"+title: "flip()"+---++A presentation where the exiting slide flips by 180 degrees, revealing the next slide on the back side.++<Demo type="flip" />++## Example++```tsx twoslash title="SlideTransition.tsx"+import { AbsoluteFill } from "remotion";++const Letter: React.FC<{+ children: React.ReactNode;+ color: string;+}> = ({ children, color }) => {+ return (+ <AbsoluteFill+ style={{+ backgroundColor: color,+ opacity: 0.9,+ justifyContent: "center",+ alignItems: "center",+ fontSize: 200,+ color: "white",+ }}+ >+ {children}+ </AbsoluteFill>+ );+};+// ---cut---+import { linearTiming, TransitionSeries } from "@remotion/transitions";+import { flip } from "@remotion/transitions/flip";++const BasicTransition = () => {+ return (+ <TransitionSeries>+ <TransitionSeries.Sequence durationInFrames={40}>+ <Letter color="#0b84f3">A</Letter>+ </TransitionSeries.Sequence>+ <TransitionSeries.Transition+ presentation={flip()}+ timing={linearTiming({ durationInFrames: 30 })}+ />+ <TransitionSeries.Sequence durationInFrames={60}>+ <Letter color="pink">B</Letter>+ </TransitionSeries.Sequence>+ </TransitionSeries>+ );+};+```++## API++Takes an object with the following properties:++### `direction`++One of `from-left`, `from-right`, `from-top`, `from-bottom`.++```tsx twoslash title="TypeScript type"+import { FlipDirection } from "@remotion/transitions/flip";++const flipDirection: FlipDirection = "from-left";+```++## See also++- [Source code for this presentation](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/flip.tsx)+- [Presentations](/docs/transitions/presentations)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex be095f4539..2a124584eb 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -423,6 +423,7 @@ module.exports = {"transitions/presentations/fade","transitions/presentations/slide","transitions/presentations/wipe",+ "transitions/presentations/flip","transitions/presentations/custom",],},diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex cbf9f9cff7..51959a7fb5 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -2493,6 +2493,13 @@ export const articles = [compId: "articles-docs-transitions-presentations-fade",crumb: "@remotion/transitions - Presentations",},+ {+ id: "transitions/presentations/flip",+ title: "flip()",+ relativePath: "docs/transitions/presentations/flip.mdx",+ compId: "articles-docs-transitions-presentations-flip",+ crumb: "@remotion/transitions - Presentations",+ },{id: "transitions/presentations/index",title: "Presentations",diff --git a/packages/docs/static/generated/articles-docs-transitions-presentations-flip.png b/packages/docs/static/generated/articles-docs-transitions-presentations-flip.pngnew file mode 100644index 0000000000..090e70b327Binary files /dev/null and b/packages/docs/static/generated/articles-docs-transitions-presentations-flip.png differdiff --git a/packages/transitions/src/presentations/flip.tsx b/packages/transitions/src/presentations/flip.tsxindex 2ed4c55f13..543614e35e 100644--- a/packages/transitions/src/presentations/flip.tsx+++ b/packages/transitions/src/presentations/flip.tsx@@ -1,9 +1,15 @@-import React, {useMemo} from 'react';import {AbsoluteFill, interpolate} from 'remotion';-import type { TransitionPresentation, TransitionPresentationComponentProps } from '../types.js';+import type {+ TransitionPresentation,+ TransitionPresentationComponentProps,+} from '../types.js';-export type FlipDirection = 'from-left' | 'from-right' | 'from-top' | 'from-bottom'+export type FlipDirection =+ | 'from-left'+ | 'from-right'+ | 'from-top'+ | 'from-bottom';type FlipPresentationProps = {direction?: FlipDirection;@@ -12,21 +18,17 @@ type FlipPresentationProps = {const Flip: React.FC<TransitionPresentationComponentProps<FlipPresentationProps>-> = ({children, presentationDirection, presentationProgress, passedProps: {- direction = "from-left",- perspective= 1000,-}}) => {+> = ({+ children,+ presentationDirection,+ presentationProgress,+ passedProps: {direction = 'from-left', perspective = 1000},+}) => {const style: React.CSSProperties = useMemo(() => {const startRotationEntering =- direction === 'from-left' ||- direction === 'from-bottom'- ? 180- : -180;+ direction === 'from-left' || direction === 'from-bottom' ? 180 : -180;const endRotationEntering =- direction === 'from-left' ||- direction === 'from-bottom'- ? -180- : 180;+ direction === 'from-left' || direction === 'from-bottom' ? -180 : 180;const rotation =presentationDirection === 'entering'@@ -34,8 +36,7 @@ const Flip: React.FC<: interpolate(presentationProgress, [0, 1], [0, endRotationEntering]);const rotateProperty =- direction === 'from-top' ||- direction === 'from-bottom'+ direction === 'from-top' || direction === 'from-bottom'? 'rotateX': 'rotateY';@@ -48,25 +49,23 @@ const Flip: React.FC<};}, [direction, presentationDirection, presentationProgress]);- const outer: React.CSSProperties = useMemo(() => {- return {- perspective,- // Make children also their backface hidden- transformStyle: 'preserve-3d',- }- }, [perspective])+ const outer: React.CSSProperties = useMemo(() => {+ return {+ perspective,+ // Make children also their backface hidden+ transformStyle: 'preserve-3d',+ };+ }, [perspective]);return (- <AbsoluteFill- style={outer}- >+ <AbsoluteFill style={outer}><AbsoluteFill style={style}>{children}</AbsoluteFill></AbsoluteFill>);};export const flip = (- props: FlipPresentationProps+ props?: FlipPresentationProps,): TransitionPresentation<FlipPresentationProps> => {- return {component: Flip, props};+ return {component: Flip, props: props ?? {}};};