AnimatePresence - Issues with exit
See original GitHub issueHi @nandorojo
maybe it’s because I didn’t understand it correctly, but I was hoping that I can also trigger the exit animation when I re-render a component.
const TextContainer = ({ index }: { index: number }) => {
return (
<AnimatePresence>
<MotiView
from={{
opacity: 0,
scale: 0.9,
translateY: 30,
}}
animate={{
opacity: 1,
scale: 1,
translateY: 0,
}}
exit={{
opacity: 0,
scale: 0.9,
}}
style={styles.textContainer}
transition={{ type: "timing", duration: 400, delay: 50 }}
>
<Text style={styles.title}>{bottles[index].name}</Text>
<Text style={styles.subtitle}>{bottles[index].slogan}</Text>
</MotiView>
</AnimatePresence>
);
};
I have created a functional component which contains AnimatePresence and a MotiView.
I call the component itself like this inside my Screen.
<TextContainer key={index) />
I only pass the index so that the component re-renders (forcing a re-render when user picks a different bottle). The index change will update the Text inside TextContainer
.
The animations works perfectly, but the exit
animation does not happen. Looks like react just remove the element and renders it once again. Maybe I did not understand the concept of exit animations correctly, but I thought, a re-render is a unmount + mount.
Issue Analytics
- State:
- Created 2 years ago
- Comments:35 (23 by maintainers)
Top Results From Across the Web
Animate Presence exit not working framer motion
The reason that this is not working is that you have to explicitly specify the key of the child that you are conditionally...
Read more >AnimatePresence exit not working for me... · Issue #493 - GitHub
Dunno if this is a bug or if i'm doing something wrong, but the exit prop does not seem to be working for...
Read more >AnimatePresence | Framer for Developers
#Exit animations ... AnimatePresence works by detecting when direct children are removed from the React tree. Any motion components contained by the removed...
Read more >Exit animation with `framer-motion` demystified
If you have worked with animation in React, you probably faced the problem of not being able to animate easily a component that...
Read more >Framer Motion exit animation is not working : r/reactjs - Reddit
I am trying to use framer-motion and want to animate an exit, this is how I am defining the motion div: {isOpen(point) ?...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pass a unique key to
MotiView
if you want it to trigger exit animations when thekey
changes. And maybe passexitBeforeEnter
toAnimatePresence
I’m revering back as this caused a harsh regression. The only solution is likely to use a
transform
array.