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.

[BUG] Layout animations do not animate completely when container is scrolled

See original GitHub issue

1. Describe the bug

I have a scrollable div, within which I have a list of motion.divs. These use AnimatePresence to animate themselves away, and each has layout set so the remaining items will animate to fill the hole left by that item.

When the div is scrolled, removing an item results in incomplete transitions and overlapping items, or other items above the removed items will move down, e.g.:

Screen Shot 2022-02-28 at 5 53 22 PM

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/s/framer-motion-layout-animation-bug-when-scrolled-pot7y3?file=/src/styles.css

4. Steps to reproduce

  1. Scroll the items in the inner div
  2. Then click an item to remove it.

Sometimes, they will overlap or leave a gap. This minimal repro renders lighter-weight components than my real app, so it can be a bit harder to see it mess up - try scrolling with a trackpad and clicking before the scroll fully settles (though in my full application, this happens reliably even when scrolling has settled).

5. Expected behavior

I expect the item that’s clicked to animate out, and the remaining items to animate into their place in the list.

6. Video or screenshots

Screen Shot 2022-02-28 at 5 59 03 PM

https://user-images.githubusercontent.com/313208/156072905-5884d634-02aa-40e2-b1a3-2c7cc49e9712.mov

7. Environment details

Chrome 98 on an M1Max MacBook Pro.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
adredcommented, Jul 19, 2022

layoutScroll doesn’t fix the issue for me.

0reactions
RannyArchercommented, Sep 14, 2022

i think you should use usePresence hook, and call safeToRemove function which is returned with isPresent which indicated the presence of element as boolean (doc: https://www.framer.com/docs/animate-presence/#usepresence) i am not sure will this work in your case or no, i wish it help you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android animation starts only after scrolling it's parent view
If your view, the one that you are animating is in the gone state, then in that case, before starting the animation, set...
Read more >
Layout animations | Framer for Developers
Animating within scroll containers. To animate layout correctly within scrollable elements, these elements must be given the layoutScroll prop. <motion ...
Read more >
Handling Scrolls with CoordinatorLayout - CodePath Cliffnotes
So long as the CoordinatorLayout is used as the primary layout, this animation effect will occur for you automatically. The floating action button...
Read more >
Triggers and animations - Webflow University
A trigger — like clicking an element or scrolling down the page — starts an animation or can even continuously animate 1 or...
Read more >
Animated - React Native
Don't modify the animated value directly. ... Gestures, like panning or scrolling, and other events can map directly to animated values ...
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