Travis Griggs
01/03/2024, 7:48 PM@Composable
fun currentTimeAsState(
updateInterval: Duration = 1.seconds,
clock: Clock = Clock.System,
): State<Instant> {
return produceState(initialValue = clock.now()) {
while (isActive) {
delay(updateInterval)
value = clock.now()
}
}
}
It's been great. I admit, I don't entirely understand how this part of Compose works.
I notice though, that if I have a screen full of many widgets that are "counting", that they seem to update independently. I assume this is because I'm creating many different TimeAsState things/objects/routines? and they're all running independently. I'd like the updates to be more synchronized throughout the app. Does it make sense to do wrap this with a CompositionLocalProvider thing, and then just have one clock as state avaiable to everyone? Or is there a better way to reduce the number as well as get some synhronization?Zach Klippenstein (he/him) [MOD]
01/03/2024, 11:30 PMZach Klippenstein (he/him) [MOD]
01/03/2024, 11:31 PMyoussef
01/04/2024, 10:07 AMZach Klippenstein (he/him) [MOD]
01/04/2024, 7:54 PM