Stylianos Gakis
05/24/2023, 3:44 PMval isImeVisible = WindowInsets.isImeVisible
LaunchedEffect(Unit) {
snapshotFlow { isImeVisible }.collectLatest {
Log.d("Tag", "it:$it")
}
}
But I am only getting this log to trigger once.
As far as I can tell, isImeVisible comes from here which in turn is stored inside AndroidWindowInsets as a MutableState, so I should be getting new emissions on my snapshotFlow due to that, but I am not getting anything.
is there something wrong with that mutable state, or could it be on my side?
I do have adjustResize
and WindowCompat.setDecorFitsSystemWindows(window, false)
fwiw.Filip Wiesner
05/24/2023, 4:00 PMisImeVisible
. So the State read happens in your composable and not in the snapshotFlow
Filip Wiesner
05/24/2023, 4:02 PMrememberUpdatedState
and then read it in your snapshotFlow
.
Something like this:
val isImeVisible by rememberUpdatedState(WindowInsets.isImeVisible)
LaunchedEffect(Unit) {
snapshotFlow { isImeVisible }.collectLatest {
Log.d("Tag", "it:$it")
}
}
Stylianos Gakis
05/24/2023, 10:30 PMsnapshotFlow { WindowInsets.isImeVisible }
but the problem in this specific case is that this getter is a composable function and you can’t do that in there.
Just tested your suggestion and it works btw, thanks a lot!Albert Chang
05/25/2023, 2:33 AMLauchedEffect(isImeVisible) {}
. Using snapshotFlow
isn't more efficient here, as the change of WindowInsets.isImeVisible
will trigger a recomposition anyway.Stylianos Gakis
05/25/2023, 7:23 AMAlbert Chang
05/25/2023, 9:23 AM