notes: fix format bar under keyboard, grid layout, compact app bar
- Commit
d90de8d56b3479d63dee3b1c2ab767f63667e0da- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-08 16:01 UTC (1 month ago)
- Parents
e6e16a5
Diff
library/ui/src/main/java/com/vayunmathur/library/ui/EditorFormatter.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/EditorFormatter.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/EditorFormatter.ktindex e0c3aafc00..2a33c46c5b 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/EditorFormatter.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/EditorFormatter.kt@@ -1,13 +1,17 @@ package com.vayunmathur.library.ui -import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.ExperimentalLayoutApi+import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.ime+import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size-import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.layout.union+import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.FormatIndentDecrease import androidx.compose.material.icons.automirrored.filled.FormatIndentIncrease@@ -188,28 +192,40 @@ fun EditorBaseButtons(formatter: EditorFormatter) { } /**- * Shared bottom-bar container for editor toolbars: a tonal [Surface] wrapping a- * [Row]. Place [EditorBaseButtons] plus any editor-specific extras inside- * [content]. Set [scrollable] for wide toolbars (e.g. office).+ * Shared bottom-bar container for editor toolbars: a tonal [Surface] wrapping+ * a [FlowRow] grid. Place [EditorBaseButtons] plus any editor-specific extras+ * inside [content]; buttons wrap onto as many rows as they need, so nothing+ * scrolls. *- * Does NOT apply window insets: as a reusable component it does not know its- * host's inset ownership. The host (MainNavigation, or a standalone root- * Scaffold) owns imePadding and keeps this bar above the keyboard.+ * The [scrollable] parameter is accepted for source compatibility and ignored:+ * every toolbar now shows all its buttons. Kept (rather than removed) so the+ * call sites in notes, email, office and the markdown/html editors compile+ * unchanged.+ *+ * The bar rides above the keyboard: a Scaffold's `bottomBar` slot is measured+ * bare and pinned to the layout bottom by M3, so the bar claims+ * `navigationBars ∪ ime` itself — union, not sum, since a visible keyboard+ * already covers the navigation bar (same fix as `BottomNavBar` in `:library`).+ * Not a [BottomAppBar]: the grid needs wrap-content height, and M3 fixes that+ * bar to a single container height. */+@OptIn(ExperimentalLayoutApi::class) @Composable fun EditorBottomBar( modifier: Modifier = Modifier,- scrollable: Boolean = false,+ @Suppress("UnusedParameter") scrollable: Boolean = false, content: @Composable RowScope.() -> Unit, ) {- Surface(modifier = modifier, tonalElevation = 3.dp) {- Row(+ Surface(+ modifier = modifier.windowInsetsPadding(WindowInsets.navigationBars.union(WindowInsets.ime)),+ tonalElevation = 3.dp,+ ) {+ FlowRow( modifier = Modifier .fillMaxWidth()- .then(if (scrollable) Modifier.horizontalScroll(rememberScrollState()) else Modifier) .padding(horizontal = 4.dp, vertical = 4.dp),- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = if (scrollable) Arrangement.Start else Arrangement.SpaceEvenly,+ horizontalArrangement = Arrangement.Start,+ verticalArrangement = Arrangement.Center, content = content, ) }
library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.ktindex c89adba963..5fcadcc2f8 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponentsExtra.kt@@ -6,9 +6,13 @@ package com.vayunmathur.library.ui +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.WindowInsets+import androidx.compose.foundation.layout.ime+import androidx.compose.foundation.layout.union import androidx.compose.material3.BottomSheetDefaults import androidx.compose.material3.ExposedDropdownMenu as Material3ExposedDropdownMenu import androidx.compose.material3.ExposedDropdownMenuBox as Material3ExposedDropdownMenuBox@@ -20,6 +24,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp // --- Theme function (distinct from the MaterialTheme object alias) --- @Composable@@ -69,12 +74,51 @@ fun NavigationDrawerItem( ) // --- Bottom app bars ---+/**+ * [BottomAppBar] that rides above the keyboard.+ *+ * A bar in a Scaffold's `bottomBar` slot must claim insets itself (M3 only+ * pads content; see `BottomNavBar` in `:library` for the same fix on the nav+ * bar). The inset is the union — not the sum — of the bar's normal one and+ * the keyboard: a visible keyboard already covers the navigation bar, so+ * padding for both would float the bar a nav bar's height above the keys.+ */ @Composable fun BottomAppBar( modifier: Modifier = Modifier, contentPadding: PaddingValues = androidx.compose.material3.BottomAppBarDefaults.ContentPadding, content: @Composable RowScope.() -> Unit,-) = androidx.compose.material3.BottomAppBar(modifier = modifier, contentPadding = contentPadding, content = content)+) = androidx.compose.material3.BottomAppBar(+ modifier = modifier,+ contentPadding = contentPadding,+ // M3's default ([BottomAppBarDefaults.windowInsets]) is system-bars only,+ // with no IME — the bar would sit behind the keyboard.+ windowInsets = androidx.compose.material3.BottomAppBarDefaults.windowInsets+ .union(WindowInsets.ime),+ content = content,+)++/**+ * Compact [FlexibleBottomAppBar]: same keyboard-riding insets as [BottomAppBar]+ * but shrunk to [barHeight] (default 48.dp, the old toolbar height) instead of+ * M3's fixed 80.dp container. With no scroll behavior `expandedHeight` is a+ * fixed height; the inner row keeps the caller's arrangement.+ */+@Composable+fun CompactBottomAppBar(+ modifier: Modifier = Modifier,+ barHeight: Dp = 48.dp,+ horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,+ content: @Composable RowScope.() -> Unit,+) = androidx.compose.material3.FlexibleBottomAppBar(+ modifier = modifier,+ contentPadding = PaddingValues(horizontal = 4.dp),+ horizontalArrangement = horizontalArrangement,+ expandedHeight = barHeight,+ windowInsets = androidx.compose.material3.BottomAppBarDefaults.windowInsets+ .union(WindowInsets.ime),+ content = content,+) @Composable fun FlexibleBottomAppBar(