Skip to content

🎥 Make videos programmatically with React

transition progress

Jonny Burger95f156b8d1b0
diff --git a/packages/docs/docs/transitions/presentations/none.mdx b/packages/docs/docs/transitions/presentations/none.mdx
new file mode 100644
index 0000000000..bfd9e1178d
--- /dev/null
+++ b/packages/docs/docs/transitions/presentations/none.mdx
@@ -0,0 +1,6 @@
+---
+crumb: "@remotion/transitions - Presentations"
+title: "none()"
+---
+
+A presentation that has no visual effect on it's own, but allows children that are in a transition state
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 1519159448..b52f2898cd 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -486,6 +486,7 @@ module.exports = {
"transitions/presentations/wipe",
"transitions/presentations/flip",
"transitions/presentations/clock-wipe",
+ "transitions/presentations/none",
{
type: "doc",
id: "transitions/presentations/cube",
diff --git a/packages/transitions/bundle.ts b/packages/transitions/bundle.ts
index 0c3259ff7a..76a5945776 100644
--- a/packages/transitions/bundle.ts
+++ b/packages/transitions/bundle.ts
@@ -5,7 +5,7 @@ if (process.env.NODE_ENV !== 'production') {
throw new Error('This script must be run using NODE_ENV=production');
}
-const presentations = ['slide', 'flip', 'wipe', 'fade', 'clock-wipe'];
+const presentations = ['slide', 'flip', 'wipe', 'fade', 'clock-wipe', 'none'];
const output = await build({
entrypoints: [
diff --git a/packages/transitions/none.js b/packages/transitions/none.js
new file mode 100644
index 0000000000..a0ce01f9e7
--- /dev/null
+++ b/packages/transitions/none.js
@@ -0,0 +1,2 @@
+// For backwards compatibility when you use `esm-wallaby`
+module.exports = require('./dist/presentations/none.js');
diff --git a/packages/transitions/package.json b/packages/transitions/package.json
index f01c51ea53..809e1c5a3f 100644
--- a/packages/transitions/package.json
+++ b/packages/transitions/package.json
@@ -89,6 +89,12 @@
"require": "./dist/presentations/clock-wipe.js",
"types": "./dist/presentations/clock-wipe.d.ts"
},
+ "./none": {
+ "module": "./dist/esm/none.mjs",
+ "import": "./dist/esm/none.mjs",
+ "require": "./dist/presentations/none.js",
+ "types": "./dist/presentations/none.d.ts"
+ },
"./package.json": "./package.json"
},
"typesVersions": {
@@ -105,6 +111,9 @@
"fade": [
"dist/presentations/fade.d.ts"
],
+ "none": [
+ "dist/presentations/none.d.ts"
+ ],
"clock-wipe": [
"dist/presentations/clock-wipe.d.ts"
]
diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsx
index f53d261135..31cfbddc69 100644
--- a/packages/transitions/src/TransitionSeries.tsx
+++ b/packages/transitions/src/TransitionSeries.tsx
@@ -7,6 +7,7 @@ import type {
} from 'remotion';
import {Internals, Sequence, useCurrentFrame, useVideoConfig} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
+import {WrapInProgressContext} from './context.js';
import {flattenChildren} from './flatten-children.js';
import {slide} from './presentations/slide.js';
import type {TransitionSeriesTransitionProps} from './types.js';
@@ -252,16 +253,26 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
{fps},
)}
>
- <UppercasePrevPresentation
- passedProps={prevPresentation.props ?? {}}
- presentationDirection="entering"
- presentationProgress={prevProgress}
- presentationDurationInFrames={prev.props.timing.getDurationInFrames(
- {fps},
- )}
+ <WrapInProgressContext
+ presentationDirection="exiting"
+ presentationProgress={nextProgress}
>
- {child}
- </UppercasePrevPresentation>
+ <UppercasePrevPresentation
+ passedProps={prevPresentation.props ?? {}}
+ presentationDirection="entering"
+ presentationProgress={prevProgress}
+ presentationDurationInFrames={prev.props.timing.getDurationInFrames(
+ {fps},
+ )}
+ >
+ <WrapInProgressContext
+ presentationDirection="entering"
+ presentationProgress={prevProgress}
+ >
+ {child}
+ </WrapInProgressContext>
+ </UppercasePrevPresentation>
+ </WrapInProgressContext>
</UppercaseNextPresentation>
</Sequence>
);
@@ -289,7 +300,12 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
{fps},
)}
>
- {child}
+ <WrapInProgressContext
+ presentationDirection="entering"
+ presentationProgress={prevProgress}
+ >
+ {child}
+ </WrapInProgressContext>
</UppercasePrevPresentation>
</Sequence>
);
@@ -317,7 +333,12 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
{fps},
)}
>
- {child}
+ <WrapInProgressContext
+ presentationDirection="exiting"
+ presentationProgress={nextProgress}
+ >
+ {child}
+ </WrapInProgressContext>
</UppercaseNextPresentation>
</Sequence>
);
diff --git a/packages/transitions/src/context.tsx b/packages/transitions/src/context.tsx
new file mode 100644
index 0000000000..456efb6af5
--- /dev/null
+++ b/packages/transitions/src/context.tsx
@@ -0,0 +1,41 @@
+import React, {useMemo} from 'react';
+
+export type TransitionState = {
+ progress: number;
+ direction: 'entering' | 'exiting';
+};
+
+const NonePresentationContext = React.createContext<TransitionState | null>(
+ null,
+);
+
+export const WrapInProgressContext: React.FC<{
+ presentationProgress: number;
+ presentationDirection: 'entering' | 'exiting';
+ children: React.ReactNode;
+}> = ({presentationDirection, presentationProgress, children}) => {
+ const value: TransitionState = useMemo(() => {
+ return {
+ progress: presentationProgress,
+ direction: presentationDirection,
+ };
+ }, [presentationDirection, presentationProgress]);
+
+ return (
+ <NonePresentationContext.Provider value={value}>
+ {children}
+ </NonePresentationContext.Provider>
+ );
+};
+
+/**
+ * Gets the progress and direction of a transition with a context() presentation.
+ */
+export const useProgress = () => {
+ const value = React.useContext(NonePresentationContext);
+ if (!value) {
+ return null;
+ }
+
+ return value;
+};
diff --git a/packages/transitions/src/index.ts b/packages/transitions/src/index.ts
index e4ef777429..c8afedc2c1 100644
--- a/packages/transitions/src/index.ts
+++ b/packages/transitions/src/index.ts
@@ -8,3 +8,5 @@ export {
TransitionPresentationComponentProps,
TransitionTiming,
} from './types.js';
+// Hooks
+export {TransitionState, useProgress} from './context.js';
diff --git a/packages/transitions/src/presentations/context.tsx b/packages/transitions/src/presentations/context.tsx
new file mode 100644
index 0000000000..6f7d6634db
--- /dev/null
+++ b/packages/transitions/src/presentations/context.tsx
@@ -0,0 +1,40 @@
+import React, {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
+import type {
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from '../types';
+
+export type NoneProps = {
+ enterStyle?: React.CSSProperties;
+ exitStyle?: React.CSSProperties;
+};
+
+const NonePresentation: React.FC<
+ TransitionPresentationComponentProps<NoneProps>
+> = ({children, presentationDirection, passedProps}) => {
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ ...(presentationDirection === 'entering'
+ ? passedProps.enterStyle
+ : passedProps.exitStyle),
+ };
+ }, [passedProps.enterStyle, passedProps.exitStyle, presentationDirection]);
+
+ return <AbsoluteFill style={style}>{children}</AbsoluteFill>;
+};
+
+/**
+ * Wraps the transition in a context so that the progress can be read from the children using a hook.
+ * @see [Documentation](https://remotion.dev/docs/transitions/presentations/context)
+ * @param {NoneProps} [props] Optional properties to define 'enterStyle' and 'exitStyle'.
+ * @returns {TransitionPresentation<NoneProps>} The transition presentation component setup.
+ */
+export const context = (
+ props?: NoneProps,
+): TransitionPresentation<NoneProps> => {
+ return {
+ component: NonePresentation,
+ props: props ?? {},
+ };
+};