https://kotlinlang.org logo
#compose
Title
# compose
z

zoha131

11/22/2021, 1:40 PM
is there any way to animate position change in compose?
c

Casey Brooks

11/22/2021, 3:22 PM
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

Doris Liu

11/22/2021, 6:31 PM
If you are trying to animate position change relative to parent layout, check out this thread: https://twitter.com/TashaRamesh/status/1461289694616907777
m

maciejciemiega

11/22/2021, 8:03 PM
@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

Doris Liu

11/22/2021, 9:59 PM
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