[QUESTION] How to Delay Children Animations with AnimatePresence
See original GitHub issueDescribe the bug
I am using AnimatePresence
on a simple example to fade in pages as they are mounted/unmounted. This works as expected. What I am struggling with is delaying the individual children animations on each page to wait until after the fade has completed first.
Using Pose and the PoseGroup
I accomplished this with code similar to this:
const Transition = posed.div({
enter: {
opacity: 1,
transition: { duration: 300 },
delay: 300,
beforeChildren: true
},
exit: { opacity: 0, transition: { duration: 300 } }
});
With Framer Motion and AnimatePresence
my code looks similar to this :
const variants = {
initial: {
opacity: 0,
},
enter: {
opacity: 1,
transition: {
duration: .3,
delay: .3,
when: 'beforeChildren',
},
},
exit: {
opacity: 0,
transition: { duration: .3 },
},
}
To Reproduce Code Sandbox - https://codesandbox.io/s/github/ryanwiemer/gatsby-using-page-transitions Github Repo - https://github.com/ryanwiemer/gatsby-using-page-transitions/blob/master/src/components/Layout.js
- Go to https://transitions.netlify.com/
- Navigate between the pages to see the basic page fade.
- Navigate to the “Animated” page. The list of items should do a stagger fade in but that animation occurs at the same time as the page fade so you don’t see it.
Expected behavior I expect the top level page fade to occur followed by the children animations. Right now all animations are occurring at the same time.
Issue Analytics
- State:
- Created 4 years ago
- Comments:17
Top GitHub Comments
I’ve been battling with this issue too. I found that if you make your child variant keys exactly the same names as your parent variant keys (in my case “enter” and “exit”), then it works!
Do not add “initial”, “animate”, or “exit” props on the child components – only the relevant “variants” prop, like so:
Note that I’m rendering this component inside of a
<AnimatePresence>
component with React Router Dom:This is an issue I’m running into. My use-case is a sidebar that expands out and needs to delay the rendering of its children until it’s full expanded.