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 and initial={false}

See original GitHub issue

I have a issue with latest version 0.14.2 where initial now is supported https://github.com/nandorojo/moti/pull/102

If you are using react native tab navigation and open a tab where the elements should be hidden on mount. What happens is that it will run the animation going from “opacity .75” to “opacity 0” while the screen is mounted. The specific screen is mounted when visited. Expected behaviour is that it should not run the animation because of initial={false}. I also tried adding animateInitialState={false} to the Something element, but that did not change anything.

const editMode = false;

<AnimatePresence initial={false}>
  {editMode && (
    <Something
      from={{ opacity: 0 }}
      animate={{ opacity: 0.75 }}
      exit={{ opacity: 0 }}
      transition={{
        type: 'timing',
        duration: 250,
      }}
    />
  )}
 </AnimatePresence>

Styles (style-components)

import styled from 'styled-components/native';
  
const Something = styled(MotiView)`
  position: absolute;
  background-color: #000000;
  border-radius: 10px;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
`;

The styles has nothing to do with it, i just pasted it anyway

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nandorojocommented, Sep 15, 2021

Thanks for the issue. I’m having a little trouble following. Can you make a snack (on iOS) reproducing, and explain what should have happened?

Can you also confirm the same happens with styled components?

0reactions
TommySorensencommented, Sep 16, 2021

Found the issue 🙄, it was error 40 🤣. My initial state was true, meaning that it was in first render true and then false just after since i got a useEffect that turned it into false.

const [editMode, setEditMode] = useState(true);

Thx for helping 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] AnimatePresence initial={false} is applied to all ... - GitHub
<AnimatePresence initial={false}> suppresses initial state for all motion components below it in the render tree, not just descendants with ...
Read more >
React - Framer motion: prevent initial prop from triggering
By setting initial={false} on AnimatePresence, components present when AnimatePresence first loads will start in their animate state.
Read more >
Example Animations » 31. Animate Presence - The Framer book
That's easy: you just set the initial value of isVisible to false (by passing a false to the useState() .) const [isVisible, setVisible]...
Read more >
Exit animation with `framer-motion` demystified
the exit one if false. This property will be injected to the AnimatedComponent by AnimatePresence thanks to the React.cloneElement API. So we ...
Read more >
Animation with Framer-Motion - #6 AnimatePresence - YouTube
Get the starter project to follow along here: https://github.com/koss-lebedev/nordic-pixelsCheatsheet explaining the differences between ...
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