gskinner / flutter_animate

Add beautiful animated effects & builders in Flutter, via an easy, highly customizable unified API.
BSD 3-Clause "New" or "Revised" License
954 stars 80 forks source link

Defer animation on list items until scrolled into view #131

Open harkairt opened 8 months ago

harkairt commented 8 months ago

Similar to https://pub.dev/packages/flutter_staggered_animations I would like to be able to only animate a list's items once they appear. Regardless of scrolling, or items changing, they should only animate for the first time.

gskinner commented 2 months ago

Sorry for the delayed response on this.

Interesting! I'll have to look at how they made that work. Worst case, I anticipate it would be pretty easy for the author of flutter_staggered_animations to create an animation type that would accept any flutter_animate instance.

Keeping open and will look into it when time permits. Feel free to take a stab at it in the meantime.

gskinner commented 1 month ago

Okay, I've been giving this a bunch of thought, and have the start of a flexible API in mind that I'm fairly sure can be implemented:

foo.animate(hiddenBehavior: myBehavior);

HiddenBehavior(behavior, visibleFraction=0.5, resetOnHide=false, keepAlive=true)

// behaviors:
HiddenBehavior.PLAY // play immediately on creation
HiddenBehavior.SKIP // skip to end if initially hidden
HiddenBehavior.PAUSE // remain paused at beginning if initially hidden
HiddenBehavior.WAIT // pause until visible

This would facilitate all of the behaviors I can think of:

Feedback is very welcome. I'm not 100% sure I love the naming of HiddenBehavior, but I think it's a bit more semantically intuitive than VisibilityBehavior (which is perhaps the more expected choice).