Skip to content

Commit

Permalink
fix: transition view
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Mar 21, 2024
1 parent daa50a1 commit fede3f6
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/components/ui/transition/factor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { forwardRef, memo, useState } from 'react'
import { m } from 'framer-motion'
import type {
HTMLMotionProps,
MotionProps,
Spring,
Target,
TargetAndTransition,
Expand Down Expand Up @@ -50,36 +51,32 @@ export const createTransitionView = (params: TransitionViewParams) => {
>

const [stableIsHydrationEnded] = useState(isHydrationEnded)

const motionProps: MotionProps = {
initial: initial || from,
animate: to,
transition: {
duration,
...(preset || microReboundPreset),
...animation.enter,
delay: enter / 1000,
},
exit: {
...from,
transition: {
duration,
...animation.exit,
delay: exit / 1000,
} as TargetAndTransition['transition'],
},
}
if (lcpOptimization && !stableIsHydrationEnded) {
return <div>{props.children}</div>
motionProps.initial = to
delete motionProps.animate
}

return (
<MotionComponent
initial={initial || from}
ref={ref}
animate={{
...to,
transition: {
duration,
...(preset || microReboundPreset),
...animation.enter,
delay: enter / 1000,
},
}}
exit={{
...from,
transition: {
duration,
...animation.exit,
delay: exit / 1000,
} as TargetAndTransition['transition'],
}}
transition={{
duration,
}}
{...rest}
>
<MotionComponent ref={ref} {...motionProps} {...rest}>
{props.children}
</MotionComponent>
)
Expand Down

0 comments on commit fede3f6

Please sign in to comment.