https://kotlinlang.org logo
Title
y

Yev Kanivets

02/09/2022, 3:44 PM
Hey! How should we approach time-dependable UI with Jetpack Compose? Let's say I have a message in chat and it has statuses (sending, sent, delivered). When it's delivered we should hide the message status in 5 seconds from its delivery time. Can I use
System.currentTimeMillis()
in if inside composable directly (I think it won't cause recomposition)? Or should I pass it as part of the state and change with old good timer? Or are there better approaches?
h

hfhbd

02/09/2022, 3:47 PM
Just use LaunchedEffect with delay(5.seconds)
c

Casey Brooks

02/09/2022, 3:48 PM
I'd steer clear of doing any computation like that directly within the composition, you're just asking for problems. That's what the various "effects" APIs are for.
produceValue
might be a good choice for this
val showStatus by produceState(true) {
    value = true
    delay(5000)
    value = false
}
👍 1
👍🏽 1