is there any way to animate position change in com...
# compose
z
is there any way to animate position change in compose?
c
Compose offers a complete set of animation APIs, described in detail in the Animation documentation page. In particular,
animateDpAsState
combined with
Modifier.offset
might be what you're looking for, but I would still look over this article to get a good idea of what's available with the animation APIs to see if another one fits your needs better https://developer.android.com/jetpack/compose/animation
d
If you are trying to animate position change relative to parent layout, check out this thread: https://twitter.com/TashaRamesh/status/1461289694616907777
m
@Doris Liu this is cool! I was literally just playing with animating Alignments. It's actually very similar, because I created an Alignment object which
.align(size, space, layoutDirection)
method returned an animated
IntOffset
calculating it from source and target Alignments'
align
methods 😅 The output is very similar, but animating this position directly is much more flexible than just animating Alignment.
d
Haha, that's a cool demo! Thanks for sharing. 🙂 Yea, animating placement using
onPlaced
would accommodate placement change for any reason, e.g. alignment, reflow, or even disappearing siblings in a Row/Column. This is also a stepping stone for shared element transition. 😛
👍 1