Modern Apps git

← Modern-Apps.git

calculator: show unit categories as a compact chip grid instead of a scrolling tab row (#549)

Commit
588247012b1d87208e47c2a5e1f278a90e74b917
Author
vayun-mathur <[email protected]>
When
2026-08-18 22:39 UTC (3 months ago)
Parents
0075030

Diff

calculator/src/main/java/com/vayunmathur/calculator/ui/UnitConverterPage.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/ui/UnitConverterPage.kt b/calculator/src/main/java/com/vayunmathur/calculator/ui/UnitConverterPage.ktindex 61ff608e36..c2cd3ab81d 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/ui/UnitConverterPage.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/ui/UnitConverterPage.kt@@ -3,10 +3,14 @@ package com.vayunmathur.calculator.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.ExperimentalLayoutApi+import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -30,17 +34,17 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.CompactTouchTargets import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.DropdownMenuItem import com.vayunmathur.library.ui.FilledTonalIconButton+import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.IconArrowDropDown import com.vayunmathur.library.ui.IconSwapLanguages import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.OutlinedTextField-import com.vayunmathur.library.ui.PrimaryScrollableTabRow import com.vayunmathur.library.ui.Spacing-import com.vayunmathur.library.ui.Tab import com.vayunmathur.library.ui.Text  /** Binds [CalculatorViewModel] to the stateless [UnitConverterScreen]. */@@ -50,9 +54,12 @@ fun UnitConverterPage(viewModel: CalculatorViewModel) { }  /**- * The units tab: a plain from/to converter with no equations, one category per tab. Stateless- * so it can be rendered from a `@Preview` โ€” see `src/screenshotTest`.+ * The units tab: a plain from/to converter with no equations. Every category is on screen at once+ * as a grid of chips, since the converter itself leaves plenty of room and a scrolling tab row hid+ * most of the twenty-odd categories. Stateless so it can be rendered from a `@Preview` โ€” see+ * `src/screenshotTest`.  */+@OptIn(ExperimentalLayoutApi::class) @Composable fun UnitConverterScreen(state: UnitConverterUiState, actions: UnitConverterActions) {     AppScaffold(@@ -60,14 +67,24 @@ fun UnitConverterScreen(state: UnitConverterUiState, actions: UnitConverterActio         alignment = AppBarAlignment.Center,     ) { padding ->         val category = state.categories.getOrNull(state.selectedCategoryIndex)-        Column(Modifier.fillMaxSize().padding(padding)) {-            PrimaryScrollableTabRow(selectedTabIndex = state.selectedCategoryIndex) {-                state.categories.forEachIndexed { index, cat ->-                    Tab(-                        selected = index == state.selectedCategoryIndex,-                        onClick = { actions.selectCategory(index) },-                        text = { Text(cat.name) },-                    )+        Column(+            Modifier+                .fillMaxSize()+                .padding(padding)+                .verticalScroll(rememberScrollState()),+        ) {+            CompactTouchTargets {+                FlowRow(+                    Modifier.fillMaxWidth().padding(horizontal = Spacing.lg, vertical = Spacing.xs),+                    horizontalArrangement = Arrangement.spacedBy(Spacing.xs),+                ) {+                    state.categories.forEachIndexed { index, cat ->+                        FilterChip(+                            selected = index == state.selectedCategoryIndex,+                            onClick = { actions.selectCategory(index) },+                            label = { Text(cat.name) },+                        )+                    }                 }             }             if (category != null) {
library/ui/src/main/java/com/vayunmathur/library/ui/MaterialFunctions.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialFunctions.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialFunctions.ktindex 2c6902ff25..65ad67638c 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialFunctions.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialFunctions.kt@@ -9,9 +9,12 @@ package com.vayunmathur.library.ui import android.content.Context import androidx.compose.material3.toShape as m3ToShape import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.remember import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp import androidx.graphics.shapes.RoundedPolygon  /**@@ -117,3 +120,19 @@ fun rememberSwipeToDismissBoxState( ) = androidx.compose.material3.rememberSwipeToDismissBoxState(     initialValue = initialValue, confirmValueChange = confirmValueChange, )++// --- Density ---+/**+ * Relaxes Material's minimum touch target, which it enforces by padding a control out to 48dp+ * without drawing anything there. A 32dp chip therefore reserves 48dp, and in a wrapping layout+ * that reads as ~16dp of stray space between rows that no spacing setting can remove.+ *+ * Only worth reaching for in a dense grid of small controls, and do not go far below [size]'s+ * default โ€” the padding exists so controls stay hittable.+ */+@Composable+fun CompactTouchTargets(size: Dp = 40.dp, content: @Composable () -> Unit) =+    CompositionLocalProvider(+        androidx.compose.material3.LocalMinimumInteractiveComponentSize provides size,+        content = content,+    )