Vaibhav Jaiswal
02/26/2024, 8:30 AMval imageIndex = produceState(0) {
if (images.size == 1) return@produceState
while (true) {
delay(interval.toLong())
value = (value + 1) % images.size
}
}
It works fine, but if I navigate to some other screen and come back, the value resets to 0
I'm using decompose for navigation
Any idea whats the problem here?
If I add this line, it works but some indexes are skipped
val index = rememberSaveable(imageIndex.value) { imageIndex.value }
Vaibhav Jaiswal
02/26/2024, 8:58 AMval imageIndex = rememberSaveable { mutableStateOf(0) }
LaunchedEffect(Unit) {
if (images.size == 1) return@LaunchedEffect
while (true) {
delay(interval.toLong())
imageIndex.value = (imageIndex.value + 1) % images.size
}
}
Arkadii Ivanov
02/26/2024, 9:15 AMVaibhav Jaiswal
02/26/2024, 9:20 AMremember
works
I dont use Component for this ui element as its a card used in a Lazy List,
Would using rememberSaveable
cause any performance issues?Arkadii Ivanov
02/26/2024, 9:23 AMVaibhav Jaiswal
02/26/2024, 9:26 AMArkadii Ivanov
02/26/2024, 9:27 AMVaibhav Jaiswal
02/26/2024, 9:27 AM