have anyone being able to create a disposable animation? I don't mean an AnimatedVisibility, but act...
m
have anyone being able to create a disposable animation? I don't mean an AnimatedVisibility, but actually a default animation when the composable is about to get disposable. Is that even possible? 🤔
s
One tricky thing with "leaving the UI" animations in general is that for the item to animate away it actually needs to be present in composition while it's animating out. AnimatedVisibility handles this well by keeping its content in composition while it's animating out. What is it that you want to do that AnimatedVisibility doesn't do for you?
m
I'm trying to create my own animated list, with entering, moving and exiting animations. The second one I can achieve with a
LookaheadLayout
. But it's tricky for me to figure it out a way of coordinating the first and last one. Like so: State: [A,B,C] -> [D,A,B] B moves to C, A moves to B, C animates out, D animates in. The animations needs to happen at the same time (using
AnimatedVisibility
I managed to do one after another). There's also another thing I want to try, using movableContent, but I was curious to see the possibilities before
d
using
AnimatedVisibility
I managed to do one after another
Glad you are trying out
LookaheadLayout
. I'd love to see a video of this to help me understand what you meant. If you provided
key
to the items in your list, you won't need movableContent.
m
I'm gonna try to prepare one
Some demo using lazy column to express the ideia. It's not much 🫣 , but it captures the stage of animating insertions and deletions 🧐 . In practice, I would have a custom layout. But the keys in the video are: I'm first animating a card being removed, and then I add the new ones to the state (which they all animate itself on entering, too). So it's a two stage transition. That's why I asked about the possibility of when the composable realizes it's been disposable, it would animate itself
d
AnimatedVisibility
unfortunately can't hook into the lookahead system until the lookahead APIs are stable. Though I do have a demo that solves a very similar problem as what you have here with a slightly modified AnimatedVisibility: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mos/lookahead/LookaheadWithDisappearingMoveableContentDemo.kt
Ideally, AnimatedVisibility would report its target size (i.e. full size or 0) in the lookahead system. That way its parent can calculate the target placement of the other children according to that target size in the lookahead pass. This allows parent and siblings to animate to their "stable" target size/position (provided by lookahead) in a coordinated manner. That's what the modified AnimatedVisibility in the demo above is trying to achieve.
m
lemme experiment with it!