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

aipok

06/25/2020, 2:31 PM
I need to make an animation for
Image
using an array of
DrawableResIds
. Let say to switch an image every second. Does anyone know how to achieve this using Compose animation API or transition? Or might there is some other way to do it?
z

Zach Klippenstein (he/him) [MOD]

06/25/2020, 2:37 PM
“Switch an image every second” is a distinct thing from animation. You could launch a coroutine that does this in a loop with a delay, or use a Flow, etc. For animating, how do you want to animate? Might be able to use the
Crossfade
composable.
a

aipok

06/25/2020, 2:39 PM
ok, I was thinking about coroutines as well. Will give it a try
Do you know a proper way to run coroutines inside composable? Or should I use something like Flow.asState from VM?
m

manueldidonna

06/25/2020, 4:26 PM
@aipok you can use
launchInComposition
and
ticker
or
delay
(give a look here)
3 Views