clark
01/19/2022, 1:24 AMaccompanist-insets
to adjust my view size according to the height of the keyboard but when the insets finish animating, they reset to 0. Anyone seen this behavior? Any ideas on how I could fix it?
I added a green box that displays the value of LocalWindowInsets.current.ime.bottom
to show it is going back to 0 at the end of each animation.Berkeli Alashov
01/20/2022, 12:31 AM0.dp
and LocalWindowInsets.current.ime.bottom
depending on keyboard visibility given by LocalWindowInsets.current.ime.isVisible
. Like this:
@Composable
fun KeyboardSpacer(
modifier: Modifier = Modifier,
confirmHeight: (Dp) -> Dp = { it },
) {
val imeVisible = LocalWindowInsets.current.ime.isVisible
val imeHeight = with(LocalDensity.current) { LocalWindowInsets.current.ime.bottom.toDp() }
val height by animateDpAsState(if (imeVisible) confirmHeight(imeHeight) else 0.dp)
Spacer(modifier.height(height))
}
Zoltan Demant
01/20/2022, 3:57 PMModifier.imePadding()
which seems to acheive the exact same thing?clark
01/20/2022, 8:16 PMModifier.imePadding()
and it is causing the issueLocalWindowInsets.current.ime.isVisible
shows that he is using itBerkeli Alashov
01/20/2022, 8:58 PMModifier.imePadding()
doesn't allow changing how much of it to apply and using LocalWindowInsets.current.ime.bottom
by itself causes a flicker at the start of hide animation.
@clark it's odd that you're getting zero from LocalWindowInsets.current.ime.bottom
at the end of animation, I just checked it myself and it's not happening on my end..Chris Miller
01/21/2022, 11:27 AM@Composable
fun HideFromIme(content: @Composable () -> Unit) {
AnimatedVisibility(
visible = !LocalWindowInsets.current.ime.isVisible,
enter = expandVertically(),
exit = shrinkVertically(),
) {
content()
}
}
clark
01/23/2022, 1:36 AMNavHost
containing several screens that were all using ProvideWindowInsets
. I took it out of the base screen they share and put the ProvideWindowInsets
around the NavHost
instead and the issue disappeared.
Thanks for the ideas everyone!