Modern Apps git

← Modern-Apps.git

library/ui: add LazyListScaffold (Scaffold+LazyColumn, contentPadding all sides, FAB/selection slots)

Commit
d4afd1a70888fcb6cc7a6b524f38b678fae4eced
Author
vayun-mathur <[email protected]>
When
2026-08-16 00:19 UTC (3 months ago)
Parents
4221571

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.ktindex 8f50220621..0af28688f5 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/LazyListScaffold.kt@@ -1,57 +1,73 @@+@file:OptIn(androidx.compose.material3.ExperimentalMaterial3Api::class)+ package com.vayunmathur.library.ui  import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.calculateEndPadding+import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.plus import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp  /**  * A scaffold whose body is a single lazily-composed list.  *- * The scaffold's [PaddingValues] are forwarded as the [LazyColumn]'s- * `contentPadding` on all four sides, so items scroll clear of the bars and- * nothing double-insets or drops the bottom inset. Only a symmetric- * [horizontalPadding] is folded onto the forwarded start/end (as- * [DetailScaffold]'s list does with `Spacing.lg`); the top and bottom are always- * exactly the scaffold's own insets.+ * Collapses the `Scaffold { pad -> LazyColumn(contentPadding = ...) { ... } }`+ * combo every list screen was writing by hand, and owns the one detail those+ * copies kept getting wrong: the [LazyColumn]'s `contentPadding` is the+ * scaffold's own [PaddingValues] on *all four sides* (mirroring [DetailScaffold]'s+ * `DetailList`), so items scroll clear of the bars and nothing double-insets or+ * drops the bottom inset. Only a symmetric [horizontalPadding] is folded onto the+ * forwarded start/end; the top and bottom are always exactly the scaffold's.  *- * Use this for a list screen that supplies its own [topBar]/[floatingActionButton]- * and custom [content] items - grouped cards, headers, selection rows - that the- * flat-item [ListPage] cannot express.+ * The caller supplies the chrome the list needs: an add-style [floatingActionButton]+ * and a swappable [topBar] - e.g. the normal-vs-selection top bar a multi-select+ * screen toggles between (see `SelectionMode.kt` for that pattern). Everything else+ * matches the shared [Scaffold] wrapper (same param names/types) so it stays a+ * drop-in replacement.  */ @Composable fun LazyListScaffold(     modifier: Modifier = Modifier,     topBar: @Composable () -> Unit = {},-    floatingActionButton: @Composable () -> Unit = {},     bottomBar: @Composable () -> Unit = {},     snackbarHost: @Composable () -> Unit = {},+    floatingActionButton: @Composable () -> Unit = {},+    floatingActionButtonPosition: FabPosition = FabPosition.End,     state: LazyListState = rememberLazyListState(),     horizontalPadding: Dp = 0.dp,     verticalArrangement: Arrangement.Vertical = Arrangement.Top,+    containerColor: Color = MaterialTheme.colorScheme.background,     content: LazyListScope.() -> Unit,-) {-    Scaffold(-        modifier = modifier,-        topBar = topBar,-        bottomBar = bottomBar,-        snackbarHost = snackbarHost,-        floatingActionButton = floatingActionButton,-    ) { innerPadding ->-        LazyColumn(-            state = state,-            modifier = Modifier.fillMaxSize(),-            contentPadding = innerPadding + PaddingValues(horizontal = horizontalPadding),-            verticalArrangement = verticalArrangement,-            content = content,-        )-    }+) = Scaffold(+    modifier,+    topBar,+    bottomBar,+    snackbarHost,+    floatingActionButton,+    floatingActionButtonPosition,+    containerColor,+) { pad ->+    val dir = LocalLayoutDirection.current+    LazyColumn(+        modifier = Modifier.fillMaxSize(),+        state = state,+        contentPadding = PaddingValues(+            start = pad.calculateStartPadding(dir) + horizontalPadding,+            end = pad.calculateEndPadding(dir) + horizontalPadding,+            top = pad.calculateTopPadding(),+            bottom = pad.calculateBottomPadding(),+        ),+        verticalArrangement = verticalArrangement,+        content = content,+    ) }