Mark
02/09/2024, 10:41 AMStylianos Gakis
02/09/2024, 10:56 AMMark
02/09/2024, 12:33 PMStylianos Gakis
02/09/2024, 12:39 PMMark
02/09/2024, 12:54 PMScaffold
at the top level where the navHost is a FragmentContainerView
containing the fragment. The fragment UI is a compose HorizontalPager
and my scrolling content is the first page. I really can’t see anything that’s consuming the insets. They are not consumed at the Scaffold level i.e. I’m able to do navigationBarsPadding
with expected results (i.e. not drawn beneath navbars). I’m not doing that though, because I know that consumes the insets. I’ll keep looking. Thanks.Stylianos Gakis
02/09/2024, 1:35 PMMark
02/09/2024, 1:38 PMnavigationBarsPadding
in the scaffold modifier then the scrollable content appears beneath the navbar, as expected. Are you saying that if I don’t do navigationBarsPadding
the scaffold will consume the navBar insets without doing anything with them?Timo Drick
02/09/2024, 2:57 PMTimo Drick
02/09/2024, 3:00 PM@Composable
fun insetsPaddingValues(insets: WindowInsets): PaddingValues {
val density = LocalDensity.current
var paddingValues by remember { mutableStateOf(insets.asPaddingValues(density)) }
Spacer(modifier = Modifier.onConsumedWindowInsetsChanged(
block = {
paddingValues = insets.exclude(it).asPaddingValues(density)
}
))
return paddingValues
}
Stylianos Gakis
02/09/2024, 3:04 PMTimo Drick
02/09/2024, 3:06 PMval contentPadding = insetsPaddingValues(WidnowInsets.safeDrawing)
LazyColumn(
contentPadding = contentPadding
) {
// list content items
}
Stylianos Gakis
02/09/2024, 3:08 PMTimo Drick
02/09/2024, 3:09 PMStylianos Gakis
02/09/2024, 3:38 PMTimo Drick
02/09/2024, 3:42 PMTimo Drick
02/09/2024, 4:03 PM@Composable
fun MainLayout(
modifier: Modifier,
mainContent: @Composable () -> Unit,
toolbarItem: @Composable (Modifier, NavIcon, Orientation) -> Unit,
) {
val main = remember(mainContent) { movableContentOf(mainContent) }
val toolbar = remember(toolbarItem) { movableContentOf(toolbarItem) }
BoxWithConstraints {
val isPortrait = maxWidth < maxHeight
if (isPortrait) {
Column(modifier.fillMaxSize()) {
Box(
Modifier
.weight(1f)
.fillMaxWidth()
.consumeWindowInsets(WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom))
) {
main()
}
Row(
Modifier
.fillMaxWidth()
.background(MaterialTheme.colors.navigationBarColor)
.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom))
.height(64.dp)
) {
NavIcon.entries.forEach { icon ->
Box(Modifier.weight(1f)) {
toolbar(Modifier.align(Alignment.Center), icon, Orientation.Horizontal)
}
}
}
}
} else {
Row(modifier.fillMaxSize()) {
Column(
modifier = Modifier
.fillMaxHeight()
.background(MaterialTheme.colors.navigationBarColor)
.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Start + WindowInsetsSides.Vertical))
.width(100.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
NavIcon.entries.forEach { icon ->
toolbar(
Modifier
.weight(1f)
.fillMaxWidth(), icon, Orientation.Vertical)
}
}
Box(
Modifier
.weight(1f)
.fillMaxHeight()
.consumeWindowInsets(WindowInsets.safeDrawing.only(WindowInsetsSides.Start))
) {
main()
}
}
}
}
}
Stylianos Gakis
02/09/2024, 8:01 PMStylianos Gakis
02/09/2024, 8:04 PMStylianos Gakis
02/09/2024, 8:10 PMMark
02/10/2024, 2:24 AM@Composable
@ReadOnlyComposable
fun isLandscape(): Boolean = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
Of course, this is only useful if MainLayout
is your whole UI.Stylianos Gakis
02/10/2024, 7:37 AMMark
02/10/2024, 7:42 AMisLandscape()
will return true if the device is in portrait and the split screen is small enough to be in landscape.Stylianos Gakis
02/10/2024, 7:44 AMMark
02/10/2024, 7:45 AMMark
02/10/2024, 7:48 AMisLandscape()
returns true according to the space available to the app, not the orientation of the device.Stylianos Gakis
02/10/2024, 8:26 AMMark
02/10/2024, 9:11 AM_LocalConfiguration_.current.orientation
accordingly, without any change in the device orientation. Are you seeing something different?Stylianos Gakis
02/10/2024, 9:43 AMMark
02/10/2024, 10:07 AMDisplay
size was also adjusted accordingly.Stylianos Gakis
02/10/2024, 11:12 AMTimo Drick
02/10/2024, 12:12 PMTimo Drick
02/10/2024, 12:36 PMMark
02/10/2024, 12:40 PMTimo Drick
02/10/2024, 4:31 PMTimo Drick
03/14/2024, 4:42 PM