Skip to content

🎥 Make videos programmatically with React

wipe transition

Jonny Burgerad168a557aa2
diff --git a/packages/example/src/Transitions/index.tsx b/packages/example/src/Transitions/index.tsx
index 2579625a5f..bc6dd71949 100644
--- a/packages/example/src/Transitions/index.tsx
+++ b/packages/example/src/Transitions/index.tsx
@@ -24,7 +24,7 @@ export const BasicTransition: React.FC = () => {
</AbsoluteFill>
</TransitionSeries.Sequence>
<TransitionSeries.Transition
- presentation={makeWipePresentation('left')}
+ presentation={makeWipePresentation({origin: 'from-left'})}
timing={makeLinearTiming({
durationInFrames: 30,
easing: Easing.bounce,
@@ -45,7 +45,7 @@ export const BasicTransition: React.FC = () => {
</AbsoluteFill>
</TransitionSeries.Sequence>
<TransitionSeries.Transition
- presentation={makeWipePresentation('top-left')}
+ presentation={makeWipePresentation({origin: 'from-left'})}
timing={makeSpringTiming({
config: {
damping: 200,
diff --git a/packages/transitions/src/presentations/Wipe.tsx b/packages/transitions/src/presentations/Wipe.tsx
index f2ffecf76a..31d5fa7e8d 100644
--- a/packages/transitions/src/presentations/Wipe.tsx
+++ b/packages/transitions/src/presentations/Wipe.tsx
@@ -8,45 +8,53 @@ import type {
const width = 1;
const height = 1;
-type WipeDirection = 'left' | 'top-left';
+type WipeDirection = 'from-left' | 'from-top-left';
type WipeProps = {
- direction: WipeDirection;
+ origin: WipeDirection;
};
-const makePathIn = (progress: number, direction: WipeDirection) => {
- if (direction === 'left') {
+const makePathIn = (progress: number, origin: WipeDirection) => {
+ if (origin === 'from-left') {
return `
- M 0 0
- L ${progress * width} 0
- L ${progress * width} ${height}
- L ${0} ${height}
- Z`;
+M 0 0
+L ${progress} 0
+L ${progress} 1
+L 0 1
+Z`;
}
- return `
+ if (origin === 'from-top-left') {
+ return `
M 0 0
-L ${progress * width * 2} 0
-L ${0} ${height * 2 * progress}
+L ${progress * 2} 0
+L 0 ${height * 2}
Z`.trim();
+ }
+
+ throw new Error(`Unknown origin ${JSON.stringify(origin)}`);
};
-const makePathOut = (progress: number, direction: WipeDirection) => {
- if (direction === 'left') {
+const makePathOut = (progress: number, origin: WipeDirection) => {
+ if (origin === 'from-left') {
return `
- M ${width} ${height}
- L ${width - progress * width} ${height}
- L ${width - progress * width} ${0}
- L ${width} ${0}
- Z
- `;
+M 1 1
+L ${1 - progress} 1
+L ${1 - progress} 0
+L 1 0
+Z
+`;
}
- return `
-M ${width} ${height}
-L ${width - 2 * progress * width} ${height}
-L ${width} ${height - 2 * progress * height}
+ if (origin === 'from-top-left') {
+ return `
+M 1 1
+L ${1 - 2 * progress} 1
+L 1 ${1 - 2 * progress}
Z
`.trim();
+ }
+
+ throw new Error(`Unknown origin ${JSON.stringify(origin)}`);
};
export const WipePresentation: React.FC<
@@ -55,7 +63,7 @@ export const WipePresentation: React.FC<
children,
presentationProgress,
presentationDirection,
- passedProps: {direction: wipeDirection},
+ passedProps: {origin: wipeDirection},
}) => {
const [clipId] = useState(() => String(random(null)));
@@ -102,10 +110,10 @@ export const WipePresentation: React.FC<
};
export const makeWipePresentation = (
- direction: WipeDirection
+ props: WipeProps
): TransitionPresentation<WipeProps> => {
return {
component: WipePresentation,
- props: {direction},
+ props,
};
};