How would I implement UI that goes away after the user hasnt interacted with it for a certain amount of time? probably making use of coroutines magic
m
mgrazianodecastro
04/13/2023, 6:47 AM
maybe using something like:
Copy code
var ticks by remember { mutableStateOf(0) }
LaunchedEffect(Unit) {
while(true) {
delay(1.seconds)
ticks++
}
}
you would derive a state from it, where when it reaches a value, the "goes away" is triggered.
And, to reset the counter, set some input gesture detector on the scope of the composable
z
Zach Klippenstein (he/him) [MOD]
04/13/2023, 6:11 PM
Another option:
Copy code
class ViewModel {
private val liveness = Channel<Unit>()
fun poke() {
liveness.trySend(Unit)
}
suspend fun run() {
liveness.receiveAsFlow()
.collectLatest {
delay(timeout)
hideStuff()
}
}
}