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
Felix Schütz
09/03/2021, 8:19 AM
I don't think the
remember
around the calculation is required. What exactly is
message
?
a
allan.conda
09/03/2021, 11:21 AM
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.