How would I implement UI that goes away after the ...
# compose
z
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
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
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()
      }
  }
}
m
like a pro /\