question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AnimatePresence - Issues with exit

See original GitHub issue

Hi @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:closed
  • Created 2 years ago
  • Comments:35 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
nandorojocommented, Sep 1, 2021

Pass a unique key to MotiView if you want it to trigger exit animations when the key changes. And maybe pass exitBeforeEnter to AnimatePresence

1reaction
nandorojocommented, Sep 1, 2021

I’m revering back as this caused a harsh regression. The only solution is likely to use a transform array.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found