Modern Apps git

← Modern-Apps.git

library: add SettingsMenuRow for action menus

Commit
db078a056a214750d578ed6f1d59eb24c2c5dec2
Author
Vayun Mathur <[email protected]>
When
2026-12-05 14:29 UTC (22 hours ago)
Parents
db4b118
The settings row family had a select row for picking a persistent
value but no row for opening a menu of actions, so apps hand-rolled
a Box plus DropdownMenu around a row (passwords did it twice).

SettingsMenuRow is that row: a SettingsRow with a dropdown arrow
whose menu items are actions, not a selection - there is no current
value to show or tick. It follows SettingsSelectRow's shape and is
generic over the item type with a label lambda.

Verified: ./gradlew :library:ui:lint :library:ui:lintVitalRelease
:library:ui:testDebugUnitTest (includes a new menu-row test in
Slice2FormSettingsTest).

Diff

library/ui/AGENTS.md
diff --git a/library/ui/AGENTS.md b/library/ui/AGENTS.mdindex b92932c2b0..51d7ff8335 100644--- a/library/ui/AGENTS.md+++ b/library/ui/AGENTS.md@@ -89,6 +89,7 @@ - com/vayunmathur/library/ui/FormComponents.kt - com/vayunmathur/library/ui/FormSection.kt - com/vayunmathur/library/ui/SettingsComponents.kt+- com/vayunmathur/library/ui/SettingsMenuRow.kt — settings row that opens a menu of actions (no persistent selection; use `SettingsSelectRow` in `SettingsComponents.kt` for picking a value) - com/vayunmathur/library/ui/SettingsSliderRow.kt - com/vayunmathur/library/ui/SettingsRadioRow.kt - com/vayunmathur/library/ui/SettingsFooter.kt
library/ui/src/main/java/com/vayunmathur/library/ui/SettingsMenuRow.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsMenuRow.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsMenuRow.ktnew file mode 100644index 0000000000..270aff7164--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsMenuRow.kt@@ -0,0 +1,54 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.layout.Box+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier++/**+ * A settings row that opens a menu of actions: a title, optional supporting+ * text and a dropdown arrow, in the same shape as [SettingsRow] and+ * [SettingsSelectRow].+ *+ * This is for “tap to do something” rows whose menu items are actions, not a+ * persistent value: there is no current selection to show or tick. Picking one+ * of [items] is picking a value — use [SettingsSelectRow] there.+ */+@Composable+fun <T> SettingsMenuRow(+    title: String,+    items: List<T>,+    itemLabel: (T) -> String,+    onItemClick: (T) -> Unit,+    modifier: Modifier = Modifier,+    supportingText: String? = null,+    enabled: Boolean = true,+    leadingContent: @Composable (() -> Unit)? = null,+) {+    var expanded by remember { mutableStateOf(false) }+    Box {+        SettingsRow(+            title = title,+            modifier = modifier,+            supportingText = supportingText,+            enabled = enabled,+            onClick = { expanded = true },+            leadingContent = leadingContent,+            trailingContent = { IconArrowDropDown() },+        )+        DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {+            items.forEach { item ->+                DropdownMenuItem(+                    text = { Text(itemLabel(item)) },+                    onClick = {+                        expanded = false+                        onItemClick(item)+                    },+                )+            }+        }+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.ktindex 38a107cd0d..3613f0cf33 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt@@ -311,6 +311,26 @@ class Slice2FormSettingsTest {         assertEquals("B", selected)     } +    // --- SettingsMenuRow ------------------------------------------------------------++    @Test+    fun `menu row opens its actions and fires the picked one`() {+        var picked: String? = null+        rule.setContent {+            SettingsMenuRow(+                title = "Slice2 Action",+                supportingText = "slice2 action hint",+                items = listOf("One", "Two"),+                itemLabel = { "Action $it" },+                onItemClick = { picked = it },+            )+        }+        rule.onNodeWithText("slice2 action hint").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Action").performClick()+        rule.onNodeWithText("Action Two").performClick()+        assertEquals("Two", picked)+    }+     // --- SettingsDivider ------------------------------------------------------------      @Test