From 9e221fdb995d5a489fb34133d2ab98d7907219bd Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Wed, 10 Apr 2024 15:47:36 -0400 Subject: feat: starting flip --- src/client/views/nodes/trails/SlideEffect.tsx | 94 ++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 17 deletions(-) (limited to 'src/client/views/nodes/trails/SlideEffect.tsx') diff --git a/src/client/views/nodes/trails/SlideEffect.tsx b/src/client/views/nodes/trails/SlideEffect.tsx index e3423069b..eee52c3ec 100644 --- a/src/client/views/nodes/trails/SlideEffect.tsx +++ b/src/client/views/nodes/trails/SlideEffect.tsx @@ -12,7 +12,7 @@ interface Props { } // TODO: add visibility detector when the slide comes into view -export default function SpringAnimation({ dir, friction, tension, mass, presEffect: presEffect, children }: Props) { +export default function SpringAnimation({ dir, friction, tension, mass, presEffect, children }: Props) { const [springs, api] = useSpring( () => ({ from: { @@ -154,7 +154,36 @@ export default function SpringAnimation({ dir, friction, tension, mass, presEffe ], }; - const flipConfig = {}; + // Flip + // const flipConfig = { + // from: { + // // opacity: 0, + // transform: `perspective(600px) rotateX(0deg)`, + // }, + // to: { + // // opacity: 1, + // transform: `perspective(600px) rotateX(180deg)`, + // config: { + // tension: tension, + // friction: friction, + // mass: mass, + // }, + // }, + // }; + + const flipConfig = { + from: { + x: 0, + }, + to: { + x: 180, + config: { + tension: tension, + friction: friction, + mass: mass, + }, + }, + }; const startAnimation = () => { if (presEffect === PresEffect.Bounce) { @@ -168,7 +197,51 @@ export default function SpringAnimation({ dir, friction, tension, mass, presEffe } }; - const flipRender = () => {}; + // const flipRender = () => { + // return ( + //
+ // 1 - o), transform }} /> + // + // {children} + // + //
+ // ); + // }; + + const flipRender = () => { + return ( +
+ `perspective(600px) rotateX(${val}deg)`) }} /> + `perspective(600px) rotateX(${val}deg)`), rotateX: '180deg' }}> + {children} + +
+ ); + }; + + const getRenderDoc = () => { + switch (presEffect) { + case PresEffect.Rotate: + return `rotate(${val}deg)`) }}>{children}; + case PresEffect.Flip: + return flipRender(); + default: + return ( + + {children} + + ); + } + }; useEffect(() => { // TODO: Control start with slide visibility instead @@ -177,18 +250,5 @@ export default function SpringAnimation({ dir, friction, tension, mass, presEffe }, 200); }, []); - return ( -
- {presEffect !== PresEffect.Rotate ? ( - - {children} - - ) : ( - `rotate(${val}deg)`) }}>{children} - )} -
- ); + return
{getRenderDoc()}
; } -- cgit v1.2.3-70-g09d2