Sebastian Höbarth
10/11/2022, 10:00 AMWindowInsets
in BottomAppBar
. The WindowInsets
padding are set after the transition to the new screen finishes and that results in a jump of the bottom bar. Is there a work arround for that? (video in thread)
Scaffold(topBar = {
...
}, bottomBar = {
// Wrap the navigation bar in a surface so the color behind the system
// navigation is equal to the container color of the navigation bar.
Surface(
color = MaterialTheme.colorScheme.surface,
tonalElevation = 6.dp
) {
BottomAppBar(
modifier = Modifier
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
)
),
Stylianos Gakis
10/11/2022, 12:24 PMStylianos Gakis
10/11/2022, 12:38 PMStylianos Gakis
10/11/2022, 12:42 PMBottomAppBar(
modifier = Modifier
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
)
),
to be
BottomAppBar(
modifier = Modifier
.consumedWindowInsets(WindowInsets(0, 0, 0, 0))
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
)
),
I don’t think this is it, but worth a tryStylianos Gakis
10/11/2022, 12:47 PMconsumedWindowInsets
is to consume more than are already consumed, not to un-consume them 😅Stylianos Gakis
10/11/2022, 12:55 PMcontentWindowInsets = WindowInsets(0, 0, 0, 0)
on your Scaffold so that it by itself is not consuming anything and lets the children deal with it themselves? And this way they won’t be considered consumed until you reach the next destination.Sebastian Höbarth
10/11/2022, 12:56 PMSebastian Höbarth
10/11/2022, 1:48 PMcontentWindowInsets = WindowInsets(0, 0, 0, 0)
fyi. this version didn’t work…Stylianos Gakis
10/11/2022, 1:54 PMcontent
is going to get, but the bottomBar is not the content lambda, it’s outside of that and those insets were consumed already at that point.
I think this is intended then, if you were consuming them there well then the system considers them consumed, it can’t know you want them unconsumed during the animation. Better to let each screen handle them themselves.
Looking really good then! So would you say you got into all this trouble due to you manually consuming the insets somewhere really high up the tree?
How did that look like exactly and why did you do that in the first place?
I’m just trying to understand myself too to make sure not to do the same mistake in the future 😅Sebastian Höbarth
10/11/2022, 2:03 PMSebastian Höbarth
10/11/2022, 2:13 PM1.3.0-beta03
to
1.3.0-rc1
and I get now an Exception when filtering my List content. When I downgrade it works fine 🙉
Are you an expert in LazyGrid as well? @Stylianos Gakis
java.lang.IllegalArgumentException: Failed requirement.
at androidx.compose.foundation.lazy.grid.LazyGridSpanLayoutProvider.getLineIndexOfItem--_Ze7BM(LazyGridSpanLayoutProvider.kt:174)
at androidx.compose.foundation.lazy.grid.LazyGridItemPlacementAnimatorKt.firstIndexInNextLineAfter(LazyGridItemPlacementAnimator.kt:495)
at androidx.compose.foundation.lazy.grid.LazyGridItemPlacementAnimatorKt.access$firstIndexInNextLineAfter(LazyGridItemPlacementAnimator.kt:1)
at androidx.compose.foundation.lazy.grid.LazyGridItemPlacementAnimator.calculateExpectedOffset-xfIKQeg(LazyGridItemPlacementAnimator.kt:383)
at androidx.compose.foundation.lazy.grid.LazyGridItemPlacementAnimator.onMeasured(LazyGridItemPlacementAnimator.kt:160)
at androidx.compose.foundation.lazy.grid.LazyGridMeasureKt.measureLazyGrid-0cYbdkg(LazyGridMeasure.kt:241)
at androidx.compose.foundation.lazy.grid.LazyGridKt$rememberLazyGridMeasurePolicy$1$1.invoke-0kLqBqw(LazyGrid.kt:334)
at androidx.compose.foundation.lazy.grid.LazyGridKt$rememberLazyGridMeasurePolicy$1$1.invoke(LazyGrid.kt:184)
at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$1$2$1.invoke-0kLqBqw(LazyLayout.kt:71)
at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$1$2$1.invoke(LazyLayout.kt:69)
at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:591)
Stylianos Gakis
10/11/2022, 2:26 PMconsumedWindowInsets
there, you may find some trouble of over-applying some spacings if you’re using that padding and insets on the same place (like say on the bottom) since it’ll be (insets + this padding) instead of (maxOf(insets, padding)) if that makes sense 😅
And unforuntately no, I haven’t used LazyGrid myself. Just make sure your keys are correct, and try and put simple Box{} as items to see if it at least works with a dead simple situation, this is my best advice 😅Stylianos Gakis
10/11/2022, 2:34 PMColumn {
Row(Modifier.weight(1f)) {
if (appState.shouldShowNavRail) {
NiANavRail(Modifier.safeDrawingPadding())
}
NiANavHost(Modifier.fillMaxHeight().weight(1f))
}
if (appState.shouldShowBottomBar) {
NiABottomBar()
}
}
And it’s the same effect, as long as you don’t need some of the Scaffold things you get as I said above.
It might simplify your app to do the same, and handle insets manually instead everywhere.
Relevant discussion hereSebastian Höbarth
10/11/2022, 2:50 PMkey
(something I have to look into later, the pagingdata is updated and the data is null, therefore I don’t have the right key, so it crashes I think…)
Yes exactly you found the line 👌
Seems like I wouldn’t need the Scaffold now. I just thought it’s best practice to use it. Snackbars… And I thought maybe there is something similar like in the View system
app:layout_behavior
where you can specify some magic and the bottombar/topbar disappears when you scroll down a list…
I have another issue with Inset padding (but not related to this issue I think).
In my ModalBottomSheet the Inset is added twice when the IME appears until a recompose happens
I don’t know if you up for it, but I can give you access to my code or we can have a huddle with screenshare, if you have time… If not, don’t worry. you helped me enough alraedyStylianos Gakis
10/11/2022, 3:23 PM