We’re trying to render relative time accurately in...
# compose
a
We’re trying to render relative time accurately in Compose:
Copy code
val displayTime = remember(message.createdTime) {
    DateUtils.getRelativeTimeSpanString(message.createdTime * 1_000).toString()
}
Text(displayTime)
When we refresh, we want to update the relative time text but it doesn’t a recomposition when the time value doesn’t change. Any idea how to handle this kind of scenario?
f
I don't think the
remember
around the calculation is required. What exactly is
message
?
a
It’s just data like a chat message. Anyway, we ended up having a “refreshTime” in the mutable state and update it everytime we refresh, so the UI uses that to update the relative time.
🤨 1