Skip to content

🎥 Make videos programmatically with React

slide transition

Jonny Burger456fabef5a0b
diff --git a/packages/example/src/Transitions/index.tsx b/packages/example/src/Transitions/index.tsx
index 5f85a1053d..fcc7ac460a 100644
--- a/packages/example/src/Transitions/index.tsx
+++ b/packages/example/src/Transitions/index.tsx
@@ -1,6 +1,7 @@
import {
makeFadePresentation,
makeLinearTiming,
+ makeSlidePresentation,
makeSpringTiming,
makeWipePresentation,
TransitionSeries,
@@ -34,6 +35,15 @@ export const BasicTransition: React.FC = () => {
<TransitionSeries.Sequence durationInFrames={30}>
<Letter color="orange"> A</Letter>
</TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={makeSlidePresentation({direction: 'from-bottom'})}
+ timing={makeLinearTiming({
+ durationInFrames: 30,
+ })}
+ />
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="pink"> ?</Letter>
+ </TransitionSeries.Sequence>
<TransitionSeries.Transition
presentation={makeWipePresentation({origin: 'from-bottom-left'})}
timing={makeLinearTiming({
diff --git a/packages/transitions/src/index.ts b/packages/transitions/src/index.ts
index fb26eddc5e..8b6b2dcd9b 100644
--- a/packages/transitions/src/index.ts
+++ b/packages/transitions/src/index.ts
@@ -1,5 +1,6 @@
// Presentations
export {makeFadePresentation} from './presentations/Fade';
+export {makeSlidePresentation} from './presentations/Slide';
export {makeWipePresentation} from './presentations/Wipe';
// Timings
export {makeLinearTiming} from './timings/linear';
diff --git a/packages/transitions/src/presentations/Slide.tsx b/packages/transitions/src/presentations/Slide.tsx
new file mode 100644
index 0000000000..b57185496f
--- /dev/null
+++ b/packages/transitions/src/presentations/Slide.tsx
@@ -0,0 +1,74 @@
+import React, {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
+import type {
+ TransitionPresentation,
+ TransitionPresentationComponentProps,
+} from '../types';
+
+type WipeDirection = 'from-left' | 'from-top' | 'from-right' | 'from-bottom';
+
+type SlideProps = {
+ direction: WipeDirection;
+};
+
+const SlidePresentation: React.FC<
+ TransitionPresentationComponentProps<SlideProps>
+> = ({
+ children,
+ presentationProgress,
+ presentationDirection,
+ passedProps: {direction: slideDirection},
+}) => {
+ const progressInDirection =
+ presentationDirection === 'in'
+ ? presentationProgress
+ : 1 - presentationProgress;
+
+ const directionStyle = useMemo((): React.CSSProperties => {
+ switch (slideDirection) {
+ case 'from-left':
+ return {
+ transform: `translateX(${progressInDirection * 100}%)`,
+ };
+ case 'from-right':
+ return {
+ transform: `translateX(-${progressInDirection * 100}%)`,
+ };
+ case 'from-top':
+ return {
+ transform: `translateY(${progressInDirection * 100}%)`,
+ };
+ case 'from-bottom':
+ return {
+ transform: `translateY(-${progressInDirection * 100}%)`,
+ };
+ default:
+ throw new Error(`Invalid direction: ${slideDirection}`);
+ }
+ }, [progressInDirection, slideDirection]);
+
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ width: '100%',
+ height: '100%',
+ justifyContent: 'center',
+ alignItems: 'center',
+ ...directionStyle,
+ };
+ }, [directionStyle]);
+
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill style={style}>{children}</AbsoluteFill>
+ </AbsoluteFill>
+ );
+};
+
+export const makeSlidePresentation = (
+ props: SlideProps
+): TransitionPresentation<SlideProps> => {
+ return {
+ component: SlidePresentation,
+ props,
+ };
+};
diff --git a/packages/transitions/src/presentations/Wipe.tsx b/packages/transitions/src/presentations/Wipe.tsx
index e7991bf0ed..88a5d38df0 100644
--- a/packages/transitions/src/presentations/Wipe.tsx
+++ b/packages/transitions/src/presentations/Wipe.tsx
@@ -80,8 +80,7 @@ type WipeDirection =
| 'from-right'
| 'from-bottom-right'
| 'from-bottom'
- | 'from-bottom-left'
- | 'from-center';
+ | 'from-bottom-left';
type WipeProps = {
origin: WipeDirection;