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.

Animate from a list

See original GitHub issue

I’m not sure this is an issue related to Moti but I can’t find a way to animate an array of cards. All our code is doing is updating a state called currentDiscoverIndex to update a list of artworks. I have a correct animation on mount but when I update the state the animation is very junky. I’m not sure if this is due to keys not being added correctly. I just can’t figure out what I’m doing wrong.

Here is my code:

Container

const Wrapper = styled(AnimatePresence)<{ containerHeight: number }>(
  ({ containerHeight }) => ({
    width: '100%',
    height: containerHeight,
  }),
);

const newArtworks = useMemo(
  () => artworks.slice(currentDiscoverIndex, currentDiscoverIndex + count),
  [artworks, currentDiscoverIndex],
);

return (
  <Wrapper containerHeight={containerHeight}>
    {newArtworks.map((card) => (
      <Card
        key={card.id}
        artwork={card}
        containerHeight={containerHeight}
      />
    ))}
  </Wrapper>
)

Card component

const Wrapper = styled(MotiView)({
  width: '100%',
  height: '100%',
});

<Wrapper
  key={artwork.id}
  from={{
    opacity: 0,
    translateX: -40,
  }}
  animate={{
    opacity: 1,
    translateX: 0,
  }}
  exit={{
    opacity: 0,
    translateX: -40,
  }}>
{ ... }
</Wrapper>

Any chance someone has an idea where I could do something wrong?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
nandorojocommented, Jan 25, 2022

I see. For starters, AnimatePresence doesn’t accept styles, so that doesn’t apply

0reactions
cdedreuillecommented, Jan 25, 2022

It is indeed working correctly now 👍 Thanks a lot for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Animate Items In List Using AnimatedList In Flutter
An AnimatedList is a List that animates the item when inserted or removed. Let's try to build something like this. Animated Widget Code...
Read more >
ListAnimate - Wolfram Language Documentation
ListAnimate[{expr1, expr2, ...}] generates an animation whose frames are the successive expri. ListAnimate[list, fps] displays fps frames per second.
Read more >
Animating List Items - CSS Animation
As a first animation we'll add a simple fade effect. The list items appear a little more gradually than before. Visually this still...
Read more >
AnimatedList (Flutter Widget of the Week) - YouTube
Use AnimatedList to make your lists more dynamic. You can use it to animate your lists when inserting or removing items.
Read more >
SwiftUI: How to animate List when … | Apple Developer Forums
I want to display a simple message while waiting for a list to be populated. Something like Loading... and when the list starts...
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