I am using framer motion, but the animation on exist for front-card is not working

//---------------------------------------------------
const FrontCard = ({ phrase, open }) => {
return (
<motion.div
onClick={() => open()}
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 1 } }}
// here is not working...
exit={{
rotateY: -180,
transition: { duration: 1, ease: "easeInOut" },
opacity: 0,
}}
>
{phrase}
</motion.div>
);
};
//---------------------------------------------------
const BackCard = ({ definition, id, term, remove }) => {
const { play, isFetching } = useVoiceContext({ text: term });
return (
<motion.div
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{
rotateY: -180,
}}
animate={{
rotateY: 0,
transition: { duration: 1, ease: "easeInOut" },
}}
>
rest...
</motion.div>
);
};
//---------------------------------------------------
const FlipCard = (props) => {
const [opened, handlers] = useDisclosure(false); // from Mantine
return (
<div
style={{
perspective: "1000px",
}}
>
<AnimatePresence>
{!opened ? (
<FrontCard {...props} />
) : (
<BackCard {...props} />
)}
</AnimatePresence>
</div>
);
};
//---------------------------------------------------
const FrontCard = ({ phrase, open }) => {
return (
<motion.div
onClick={() => open()}
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 1 } }}
// here is not working...
exit={{
rotateY: -180,
transition: { duration: 1, ease: "easeInOut" },
opacity: 0,
}}
>
{phrase}
</motion.div>
);
};
//---------------------------------------------------
const BackCard = ({ definition, id, term, remove }) => {
const { play, isFetching } = useVoiceContext({ text: term });
return (
<motion.div
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{
rotateY: -180,
}}
animate={{
rotateY: 0,
transition: { duration: 1, ease: "easeInOut" },
}}
>
rest...
</motion.div>
);
};
//---------------------------------------------------
const FlipCard = (props) => {
const [opened, handlers] = useDisclosure(false); // from Mantine
return (
<div
style={{
perspective: "1000px",
}}
>
<AnimatePresence>
{!opened ? (
<FrontCard {...props} />
) : (
<BackCard {...props} />
)}
</AnimatePresence>
</div>
);
};
7 Replies
vince
vince4mo ago
i'd put this in #front-end (unless someone said to put it here, but this looks like a frontend post to me)
missymae#2783
missymae#27834mo ago
motion elements need a unique key prop to animate presence.
Ali
Ali4mo ago
amazing! I tried it, issue fixed! but now it triggers another issue
Ali
Ali4mo ago
missymae#2783
missymae#27834mo ago
try adding mode='wait' in the AnimatePresence component. It looks like both sides are rendered at the same time for a moment.
Ali
Ali4mo ago
amazing again! there is a little pause (empty space) before the back-card starts flipping, any idea?
Ali
Ali4mo ago