Hey! How should we approach time-dependable UI wit...
# compose
y
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
Just use LaunchedEffect with delay(5.seconds)
c
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
Copy code
val showStatus by produceState(true) {
    value = true
    delay(5000)
    value = false
}
👍 1
👍🏽 1