ui: fix expanded tabbed-pager inset and cap detail width
- Commit
497c5f65528c3b9308f5cc19823855d6dfee16eb- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 18:25 UTC (16 days ago)
- Parents
d3c186f
TabbedPagerScaffold's expanded branches forwarded the full scaffold padding (top included) while consuming only start, so every inner page's top bar claimed the status-bar inset a second time - a dead 24-32dp band on tablets for all 14 tabbed apps. Expanded branches now drop the forwarded top and consume it, like the compact branch already did for the bottom. DetailColumn/SetupColumn capped their width only by pane margins (24dp), stretching ~65 form screens edge-to-edge on >=840dp windows. They now centre at DesktopContentMaxWidth (720dp) with a fullBleed opt-out; DetailList stays uncapped - music's detail screens use DetailLazyColumn and are unaffected, and a caller audit found no screen that needs full width. Verified: :library:ui compile + testDebugUnitTest (1055 tests, 0 failures; no test encoded the old behaviour).
Diff
library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.ktindex 0577e08374..23f7228fe0 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/DetailScaffold.kt@@ -1,6 +1,7 @@ package com.vayunmathur.library.ui import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ColumnScope@@ -12,13 +13,16 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLayoutDirection+import androidx.compose.ui.unit.Dp import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.NavKey @@ -38,6 +42,12 @@ import com.vayunmathur.library.util.NavKey * The content lambda runs in a [ColumnScope] that is already scrolling; use * [DetailLazyColumn] instead when the body is itself a long list that should * lazily compose.+ *+ * On wide windows the scrolling column is centred and capped at+ * [DesktopContentMaxWidth] so forms and detail blocks keep a readable+ * measure instead of stretching edge to edge. Pass [fullBleed] = true only+ * for a detail whose content genuinely needs the full window width (a+ * full-width hero or media surface); the lazy variant is never capped. */ @Composable fun DetailScaffold(@@ -51,6 +61,7 @@ fun DetailScaffold( actions: @Composable RowScope.() -> Unit = {}, scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {},+ fullBleed: Boolean = false, content: @Composable ColumnScope.() -> Unit, ) = AppScaffold( title = title,@@ -64,7 +75,7 @@ fun DetailScaffold( scrollBehavior = scrollBehavior, bottomBar = bottomBar, ) { pad ->- DetailColumn(pad, fillHeight = false, content)+ DetailColumn(pad, fillHeight = false, fullBleed = fullBleed, content) } /** [DetailScaffold] with a title slot, for a styled or truncated heading. */@@ -81,6 +92,7 @@ fun DetailScaffold( scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {}, fillHeight: Boolean = false,+ fullBleed: Boolean = false, content: @Composable ColumnScope.() -> Unit, ) = AppScaffold( title = title,@@ -94,7 +106,7 @@ fun DetailScaffold( scrollBehavior = scrollBehavior, bottomBar = bottomBar, ) { pad ->- DetailColumn(pad, fillHeight, content)+ DetailColumn(pad, fillHeight, fullBleed, content) } /** [DetailScaffold] for a screen that owns a back stack, wiring the back button to it. */@@ -110,6 +122,7 @@ fun <T : NavKey> DetailScaffold( actions: @Composable RowScope.() -> Unit = {}, scrollBehavior: TopAppBarScrollBehavior? = null, bottomBar: @Composable () -> Unit = {},+ fullBleed: Boolean = false, content: @Composable ColumnScope.() -> Unit, ) = DetailScaffold( title = title,@@ -122,6 +135,7 @@ fun <T : NavKey> DetailScaffold( actions = actions, scrollBehavior = scrollBehavior, bottomBar = bottomBar,+ fullBleed = fullBleed, content = content, ) @@ -208,38 +222,57 @@ fun <T : NavKey> DetailLazyColumn( private fun DetailColumn( pad: PaddingValues, fillHeight: Boolean,+ fullBleed: Boolean, content: @Composable ColumnScope.() -> Unit, ) {+ // Centre the scrolling column at a readable measure on wide windows;+ // fullBleed details keep the whole width. The cap lives here, on the+ // scrolling form column only - DetailList (lazy) content is not capped.+ val contentMaxWidth: Dp = if (fullBleed) Dp.Infinity else DesktopContentMaxWidth if (!fillHeight) {- Column(+ Box( modifier = Modifier .fillMaxSize()- .padding(pad)- .padding(horizontal = paneContentMargin())- .verticalScroll(rememberScrollState()),- verticalArrangement = Arrangement.spacedBy(Spacing.md),- content = content,- )+ .padding(pad),+ contentAlignment = Alignment.TopCenter,+ ) {+ Column(+ modifier = Modifier+ .widthIn(max = contentMaxWidth)+ .fillMaxWidth()+ .padding(horizontal = paneContentMargin())+ .verticalScroll(rememberScrollState()),+ verticalArrangement = Arrangement.spacedBy(Spacing.md),+ content = content,+ )+ } return } // Constrain the scrolling column to be at least as tall as the viewport so a // weighted child in [content] can fill the empty space below the blocks (and // still scroll once the content outgrows the screen).- BoxWithConstraints(+ Box( modifier = Modifier .fillMaxSize() .padding(pad),+ contentAlignment = Alignment.TopCenter, ) {- val minContentHeight = maxHeight- Column(+ BoxWithConstraints( modifier = Modifier- .fillMaxWidth()- .padding(horizontal = paneContentMargin())- .verticalScroll(rememberScrollState())- .heightIn(min = minContentHeight),- verticalArrangement = Arrangement.spacedBy(Spacing.md),- content = content,- )+ .widthIn(max = contentMaxWidth)+ .fillMaxWidth(),+ ) {+ val minContentHeight = maxHeight+ Column(+ modifier = Modifier+ .fillMaxWidth()+ .padding(horizontal = paneContentMargin())+ .verticalScroll(rememberScrollState())+ .heightIn(min = minContentHeight),+ verticalArrangement = Arrangement.spacedBy(Spacing.md),+ content = content,+ )+ } } }
library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.ktindex 5122d0bc8b..2792104488 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/SetupScaffold.kt@@ -1,6 +1,7 @@ package com.vayunmathur.library.ui import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.PaddingValues@@ -9,11 +10,13 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.Dp import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.NavKey @@ -42,6 +45,10 @@ data class SetupAction( * [primaryAction] is the way forward and renders filled; [secondaryAction] is the escape * hatch and renders as text. Pass neither for a screen the user cannot act on yet - a * progress step, say - and the footer disappears rather than showing a dead button.+ *+ * On wide windows the scrolling column is centred and capped at+ * [DesktopContentMaxWidth]; pass [fullBleed] = true only for a step whose+ * content genuinely needs the full window width. */ @Composable fun SetupScaffold(@@ -54,6 +61,7 @@ fun SetupScaffold( primaryAction: SetupAction? = null, secondaryAction: SetupAction? = null, scrollBehavior: TopAppBarScrollBehavior? = null,+ fullBleed: Boolean = false, content: @Composable ColumnScope.() -> Unit = {}, ) = AppScaffold( title = "",@@ -63,7 +71,7 @@ fun SetupScaffold( scrollBehavior = scrollBehavior, bottomBar = { SetupFooter(primaryAction, secondaryAction) }, ) { pad ->- SetupColumn(pad, title, subtitle, icon, content)+ SetupColumn(pad, title, subtitle, icon, fullBleed, content) } /** [SetupScaffold] for a screen that owns a back stack, wiring the back button to it. */@@ -77,6 +85,7 @@ fun <T : NavKey> SetupScaffold( primaryAction: SetupAction? = null, secondaryAction: SetupAction? = null, scrollBehavior: TopAppBarScrollBehavior? = null,+ fullBleed: Boolean = false, content: @Composable ColumnScope.() -> Unit = {}, ) = SetupScaffold( title = title,@@ -87,6 +96,7 @@ fun <T : NavKey> SetupScaffold( primaryAction = primaryAction, secondaryAction = secondaryAction, scrollBehavior = scrollBehavior,+ fullBleed = fullBleed, content = content, ) @@ -96,32 +106,43 @@ private fun SetupColumn( title: String, subtitle: String?, icon: (@Composable () -> Unit)?,+ fullBleed: Boolean, content: @Composable ColumnScope.() -> Unit, ) {- Column(+ // Centre the scrolling column at a readable measure on wide windows;+ // fullBleed steps keep the whole width.+ val contentMaxWidth: Dp = if (fullBleed) Dp.Infinity else DesktopContentMaxWidth+ Box( modifier = Modifier .fillMaxSize()- .padding(pad)- .padding(horizontal = paneContentMargin())- .verticalScroll(rememberScrollState()),- verticalArrangement = Arrangement.spacedBy(Spacing.md),+ .padding(pad),+ contentAlignment = Alignment.TopCenter, ) {- if (icon != null) {+ Column(+ modifier = Modifier+ .widthIn(max = contentMaxWidth)+ .fillMaxWidth()+ .padding(horizontal = paneContentMargin())+ .verticalScroll(rememberScrollState()),+ verticalArrangement = Arrangement.spacedBy(Spacing.md),+ ) {+ if (icon != null) {+ Spacer(Modifier.padding(top = Spacing.sm))+ icon()+ }+ Text(title, style = MaterialTheme.typography.displaySmall)+ if (subtitle != null) {+ Text(+ subtitle,+ style = MaterialTheme.typography.bodyLarge,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ // The gap between the heading block and whatever the step actually asks for. Spacer(Modifier.padding(top = Spacing.sm))- icon()- }- Text(title, style = MaterialTheme.typography.displaySmall)- if (subtitle != null) {- Text(- subtitle,- style = MaterialTheme.typography.bodyLarge,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )+ content()+ Spacer(Modifier.padding(bottom = Spacing.xl)) }- // The gap between the heading block and whatever the step actually asks for.- Spacer(Modifier.padding(top = Spacing.sm))- content()- Spacer(Modifier.padding(bottom = Spacing.xl)) } }
library/ui/src/main/java/com/vayunmathur/library/ui/TabbedPagerScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/TabbedPagerScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/TabbedPagerScaffold.ktindex 2c161baba7..ecaae5959d 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/TabbedPagerScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/TabbedPagerScaffold.kt@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.foundation.layout.fillMaxHeight@@ -101,11 +102,22 @@ fun TabbedPagerScaffold( topBar = topBar, bottomBar = leadingBottomBar, ) { padding ->- // Rail owns the start inset; the pager consumes the rest. The- // forwarded space is consumed for the same reason as below:- // the rail already covers the navigation bar, so a page's own- // scaffold would otherwise inset for it again.- Row(Modifier.padding(padding)) {+ // Do not forward the top padding: inner pages own their top+ // bar and consume the status-bar inset themselves, so+ // forwarding it here insets the status bar twice and leaves+ // a dead band above the page (the compact branch below+ // forwards only the bottom for the same reason). The top is+ // consumed on the pager instead, as is the start the rail+ // already covers, so a page's own scaffold does not inset+ // for either again.+ val direction = LocalLayoutDirection.current+ val start = padding.calculateStartPadding(direction)+ val end = padding.calculateEndPadding(direction)+ val top = padding.calculateTopPadding()+ val bottom = padding.calculateBottomPadding()+ Row(+ Modifier.padding(start = start, end = end, bottom = bottom),+ ) { NavigationRail(Modifier.fillMaxHeight()) { tabs.forEachIndexed { index, tab -> NavigationRailItem(@@ -116,12 +128,13 @@ fun TabbedPagerScaffold( ) } }- val start = padding.calculateStartPadding(LocalLayoutDirection.current) HorizontalPager( state = pagerState, modifier = Modifier .weight(1f)- .consumeWindowInsets(PaddingValues(start = start)),+ .consumeWindowInsets(+ PaddingValues(start = start, top = top),+ ), ) { page -> tabs[page].content() } } }@@ -234,9 +247,17 @@ fun <T : NavKey> TabbedPagerScaffold( topBar = topBar, bottomBar = leadingBottomBar, ) { padding ->- // Rail owns the start inset; content consumes the rest (same- // forwarding as the pager overload's expanded branch).- Row(Modifier.padding(padding)) {+ // Same expanded forwarding as the pager overload: the top is not+ // forwarded (inner pages own their top bar) and is consumed on+ // the content container together with the start the rail covers.+ val direction = LocalLayoutDirection.current+ val start = padding.calculateStartPadding(direction)+ val end = padding.calculateEndPadding(direction)+ val top = padding.calculateTopPadding()+ val bottom = padding.calculateBottomPadding()+ Row(+ Modifier.padding(start = start, end = end, bottom = bottom),+ ) { NavigationRail(Modifier.fillMaxHeight()) { tabs.forEach { tab -> NavigationRailItem(@@ -247,12 +268,13 @@ fun <T : NavKey> TabbedPagerScaffold( ) } }- val start = padding.calculateStartPadding(LocalLayoutDirection.current) Box( Modifier .weight(1f) .fillMaxHeight()- .consumeWindowInsets(PaddingValues(start = start)),+ .consumeWindowInsets(+ PaddingValues(start = start, top = top),+ ), ) { content(current) } } }