Skip to content

🎥 Make videos programmatically with React

`@remotion/transitions`: Allow customization of container styles

Jonny Burger2f7fdc8ce4f1
diff --git a/packages/docs/docs/transitions/presentations/clock-wipe.mdx b/packages/docs/docs/transitions/presentations/clock-wipe.mdx
index b61c95bd2e..39385e2d07 100644
--- a/packages/docs/docs/transitions/presentations/clock-wipe.mdx
+++ b/packages/docs/docs/transitions/presentations/clock-wipe.mdx
@@ -61,7 +61,31 @@ const BasicTransition = () => {
## API
-Accepts an object composed of `width` and `height`, which should be set to the width and height of the video.
+Accepts an object with the following options:
+
+### `width`
+
+Should be set to the width of the video.
+
+### `height`
+
+Should be set to the height of the video.
+
+### `outerEnterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the outer element when the scene is is entering.
+
+### `outerExitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the outer element when the scene is exiting.
+
+### `innerEnterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the inner element when the scene is entering.
+
+### `innerExitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the inner element when the scene is exiting.
## See also
diff --git a/packages/docs/docs/transitions/presentations/fade.mdx b/packages/docs/docs/transitions/presentations/fade.mdx
index 15faf29e78..c677bfea14 100644
--- a/packages/docs/docs/transitions/presentations/fade.mdx
+++ b/packages/docs/docs/transitions/presentations/fade.mdx
@@ -56,7 +56,15 @@ const BasicTransition = () => {
## API
-This API has no options.
+An object which takes:
+
+### `enterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the container element when the scene is is entering.
+
+### `exitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the container element when the scene is exiting.
## See also
diff --git a/packages/docs/docs/transitions/presentations/flip.mdx b/packages/docs/docs/transitions/presentations/flip.mdx
index c8dae47e0a..ccdadc5a11 100644
--- a/packages/docs/docs/transitions/presentations/flip.mdx
+++ b/packages/docs/docs/transitions/presentations/flip.mdx
@@ -70,6 +70,22 @@ import { FlipDirection } from "@remotion/transitions/flip";
const flipDirection: FlipDirection = "from-left";
```
+### `outerEnterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the outer element when the scene is is entering.
+
+### `outerExitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the outer element when the scene is exiting.
+
+### `innerEnterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the inner element when the scene is entering.
+
+### `innerExitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the inner element when the scene is exiting.
+
## See also
- [Source code for this presentation](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/flip.tsx)
diff --git a/packages/docs/docs/transitions/presentations/slide.mdx b/packages/docs/docs/transitions/presentations/slide.mdx
index ca08b3d987..92daafa688 100644
--- a/packages/docs/docs/transitions/presentations/slide.mdx
+++ b/packages/docs/docs/transitions/presentations/slide.mdx
@@ -68,6 +68,14 @@ import { SlideDirection } from "@remotion/transitions/slide";
const slideDirection: SlideDirection = "from-left";
```
+### `enterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the container when the scene is is entering.
+
+### `exitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the container when the scene is exiting.
+
## See also
- [Source code for this presentation](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/slide.tsx)
diff --git a/packages/docs/docs/transitions/presentations/wipe.mdx b/packages/docs/docs/transitions/presentations/wipe.mdx
index 51f08dec88..64b43913cf 100644
--- a/packages/docs/docs/transitions/presentations/wipe.mdx
+++ b/packages/docs/docs/transitions/presentations/wipe.mdx
@@ -68,6 +68,22 @@ import { WipeDirection } from "@remotion/transitions/wipe";
const wipeDirection: WipeDirection = "from-left";
```
+### `outerEnterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the outer element when the scene is is entering.
+
+### `outerExitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the outer element when the scene is exiting.
+
+### `innerEnterStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the inner element when the scene is entering.
+
+### `innerExitStyle?`<AvailableFrom v="4.0.84"/>
+
+The style of the inner element when the scene is exiting.
+
## See also
- [Source code for this presentation](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/wipe.tsx)
diff --git a/packages/transitions/src/presentations/clock-wipe.tsx b/packages/transitions/src/presentations/clock-wipe.tsx
index 3a5e4b54a3..536a74e87f 100644
--- a/packages/transitions/src/presentations/clock-wipe.tsx
+++ b/packages/transitions/src/presentations/clock-wipe.tsx
@@ -10,6 +10,10 @@ import type {
export type ClockWipeProps = {
width: number;
height: number;
+ outerEnterStyle?: React.CSSProperties;
+ outerExitStyle?: React.CSSProperties;
+ innerEnterStyle?: React.CSSProperties;
+ innerExitStyle?: React.CSSProperties;
};
const ClockWipePresentation: React.FC<
@@ -36,11 +40,29 @@ const ClockWipePresentation: React.FC<
height: '100%',
clipPath:
presentationDirection === 'exiting' ? undefined : `url(#${clipId})`,
+ ...(presentationDirection === 'entering'
+ ? passedProps.innerEnterStyle
+ : passedProps.innerExitStyle),
};
- }, [clipId, presentationDirection]);
+ }, [
+ clipId,
+ passedProps.innerEnterStyle,
+ passedProps.innerExitStyle,
+ presentationDirection,
+ ]);
+
+ const outerStyle = useMemo(() => {
+ return presentationDirection === 'entering'
+ ? passedProps.outerEnterStyle
+ : passedProps.outerExitStyle;
+ }, [
+ passedProps.outerEnterStyle,
+ passedProps.outerExitStyle,
+ presentationDirection,
+ ]);
return (
- <AbsoluteFill>
+ <AbsoluteFill style={outerStyle}>
<AbsoluteFill style={style}>{children}</AbsoluteFill>
{presentationDirection === 'exiting' ? null : (
<AbsoluteFill>
diff --git a/packages/transitions/src/presentations/fade.tsx b/packages/transitions/src/presentations/fade.tsx
index 56cb367e4a..12bf9ca8e6 100644
--- a/packages/transitions/src/presentations/fade.tsx
+++ b/packages/transitions/src/presentations/fade.tsx
@@ -5,24 +5,31 @@ import type {
TransitionPresentationComponentProps,
} from '../types.js';
-// No options: https://www.totaltypescript.com/the-empty-object-type-in-typescript
-export type FadeProps = Record<string, never>;
+export type FadeProps = {
+ enterStyle?: React.CSSProperties;
+ exitStyle?: React.CSSProperties;
+};
const FadePresentation: React.FC<
TransitionPresentationComponentProps<FadeProps>
-> = ({children, presentationDirection, presentationProgress}) => {
+> = ({children, presentationDirection, presentationProgress, passedProps}) => {
const isEntering = presentationDirection === 'entering';
const style: React.CSSProperties = useMemo(() => {
return {
opacity: isEntering ? presentationProgress : 1,
+ ...(presentationDirection === 'entering'
+ ? passedProps.enterStyle
+ : passedProps.exitStyle),
};
- }, [isEntering, presentationProgress]);
+ }, [
+ isEntering,
+ passedProps.enterStyle,
+ passedProps.exitStyle,
+ presentationDirection,
+ presentationProgress,
+ ]);
- return (
- <AbsoluteFill>
- <AbsoluteFill style={style}>{children}</AbsoluteFill>
- </AbsoluteFill>
- );
+ return <AbsoluteFill style={style}>{children}</AbsoluteFill>;
};
export const fade = (props?: FadeProps): TransitionPresentation<FadeProps> => {
diff --git a/packages/transitions/src/presentations/flip.tsx b/packages/transitions/src/presentations/flip.tsx
index 019544fdd1..26268ab618 100644
--- a/packages/transitions/src/presentations/flip.tsx
+++ b/packages/transitions/src/presentations/flip.tsx
@@ -14,13 +14,24 @@ export type FlipDirection =
export type FlipProps = {
direction?: FlipDirection;
perspective?: number;
+ outerEnterStyle?: React.CSSProperties;
+ outerExitStyle?: React.CSSProperties;
+ innerEnterStyle?: React.CSSProperties;
+ innerExitStyle?: React.CSSProperties;
};
const Flip: React.FC<TransitionPresentationComponentProps<FlipProps>> = ({
children,
presentationDirection,
presentationProgress,
- passedProps: {direction = 'from-left', perspective = 1000},
+ passedProps: {
+ direction = 'from-left',
+ perspective = 1000,
+ innerEnterStyle,
+ innerExitStyle,
+ outerEnterStyle,
+ outerExitStyle,
+ },
}) => {
const style: React.CSSProperties = useMemo(() => {
const startRotationEntering =
@@ -44,16 +55,28 @@ const Flip: React.FC<TransitionPresentationComponentProps<FlipProps>> = ({
transform: `${rotateProperty}(${rotation}deg)`,
backfaceVisibility: 'hidden',
WebkitBackfaceVisibility: 'hidden',
+ ...(presentationDirection === 'entering'
+ ? innerEnterStyle
+ : innerExitStyle),
};
- }, [direction, presentationDirection, presentationProgress]);
+ }, [
+ direction,
+ innerEnterStyle,
+ innerExitStyle,
+ presentationDirection,
+ presentationProgress,
+ ]);
const outer: React.CSSProperties = useMemo(() => {
return {
perspective,
// Make children also their backface hidden
transformStyle: 'preserve-3d',
+ ...(presentationDirection === 'entering'
+ ? outerEnterStyle
+ : outerExitStyle),
};
- }, [perspective]);
+ }, [outerEnterStyle, outerExitStyle, perspective, presentationDirection]);
return (
<AbsoluteFill style={outer}>
diff --git a/packages/transitions/src/presentations/slide.tsx b/packages/transitions/src/presentations/slide.tsx
index 7b40e412b6..aca139fcd2 100644
--- a/packages/transitions/src/presentations/slide.tsx
+++ b/packages/transitions/src/presentations/slide.tsx
@@ -13,6 +13,8 @@ export type SlideDirection =
export type SlideProps = {
direction?: SlideDirection;
+ exitStyle?: React.CSSProperties;
+ enterStyle?: React.CSSProperties;
};
const SlidePresentation: React.FC<
@@ -21,7 +23,7 @@ const SlidePresentation: React.FC<
children,
presentationProgress,
presentationDirection,
- passedProps: {direction = 'from-left'},
+ passedProps: {direction = 'from-left', enterStyle, exitStyle},
}) => {
const directionStyle = useMemo((): React.CSSProperties => {
if (presentationDirection === 'exiting') {
@@ -76,14 +78,11 @@ const SlidePresentation: React.FC<
justifyContent: 'center',
alignItems: 'center',
...directionStyle,
+ ...(presentationDirection === 'entering' ? enterStyle : exitStyle),
};
- }, [directionStyle]);
+ }, [directionStyle, enterStyle, exitStyle, presentationDirection]);
- return (
- <AbsoluteFill>
- <AbsoluteFill style={style}>{children}</AbsoluteFill>
- </AbsoluteFill>
- );
+ return <AbsoluteFill style={style}>{children}</AbsoluteFill>;
};
export const slide = (
diff --git a/packages/transitions/src/presentations/wipe.tsx b/packages/transitions/src/presentations/wipe.tsx
index a9c97e91ab..b0251272f9 100644
--- a/packages/transitions/src/presentations/wipe.tsx
+++ b/packages/transitions/src/presentations/wipe.tsx
@@ -84,6 +84,10 @@ export type WipeDirection =
export type WipeProps = {
direction?: WipeDirection;
+ outerEnterStyle?: React.CSSProperties;
+ outerExitStyle?: React.CSSProperties;
+ innerEnterStyle?: React.CSSProperties;
+ innerExitStyle?: React.CSSProperties;
};
const makePathOut = (progress: number, direction: WipeDirection) => {
@@ -159,7 +163,13 @@ const WipePresentation: React.FC<
children,
presentationProgress,
presentationDirection,
- passedProps: {direction = 'from-left'},
+ passedProps: {
+ direction = 'from-left',
+ innerEnterStyle,
+ innerExitStyle,
+ outerEnterStyle,
+ outerExitStyle,
+ },
}) => {
const [clipId] = useState(() => String(random(null)));
@@ -180,8 +190,17 @@ const WipePresentation: React.FC<
justifyContent: 'center',
alignItems: 'center',
clipPath: `url(#${clipId})`,
+ ...(presentationDirection === 'entering'
+ ? innerEnterStyle
+ : innerExitStyle),
};
- }, [clipId]);
+ }, [clipId, innerEnterStyle, innerExitStyle, presentationDirection]);
+
+ const outerStyle = useMemo(() => {
+ return presentationDirection === 'entering'
+ ? outerEnterStyle
+ : outerExitStyle;
+ }, [outerEnterStyle, outerExitStyle, presentationDirection]);
const svgStyle: React.CSSProperties = useMemo(() => {
return {
@@ -192,7 +211,7 @@ const WipePresentation: React.FC<
}, []);
return (
- <AbsoluteFill>
+ <AbsoluteFill style={outerStyle}>
<AbsoluteFill style={style}>{children}</AbsoluteFill>
<AbsoluteFill>
<svg viewBox="0 0 1 1" style={svgStyle}>