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

Alexandru Hadăr

02/06/2023, 6:03 PM
I have a list of
strings
and I’m using
Crossfade
to animate between them (I’m showing 1 string at a time), like this:
Copy code
var index by remember { mutableStateOf(0) }    

Crossfade(targetState = index) {
    Text(strings[it])
 }
Is there something that takes index from
0
to
strings.size
incrementally each second? What I’m doing so far is
Copy code
LaunchedEffect(news) {
            while (isActive) {
                delay(1_000)
                index += 1
                index %= news.size
            }
        }
However, I’m not sure if this is the right approach. Is there something like
animateFloatAsState
for
int
, for what I need?
s

Stylianos Gakis

02/06/2023, 7:47 PM
Use
produceState
instead. You are in a suspending context there so you can do
while (isActive)
and in there delay and increment the value returning it to 0 when you reach the text's size.
3 Views