From da892ac49003ab24ec9360e14a2b3054cd2928c0 Mon Sep 17 00:00:00 2001 From: "Jack Boswell (boswelja)" Date: Wed, 6 Dec 2023 19:46:37 +1300 Subject: [PATCH] String-ify overflow item --- .../material3/DefaultMenuItems.kt | 27 +++++++++++++++++++ .../src/androidMain/res/values/strings.xml | 4 +++ .../material3/DefaultMenuItems.kt | 18 +++++++++++++ .../material3/TopAppBarMenuItems.kt | 11 ++++---- 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 material3/src/androidMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt create mode 100644 material3/src/androidMain/res/values/strings.xml create mode 100644 material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt diff --git a/material3/src/androidMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt b/material3/src/androidMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt new file mode 100644 index 0000000..536a33a --- /dev/null +++ b/material3/src/androidMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt @@ -0,0 +1,27 @@ +package com.boswelja.menuprovider.material3 + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.MoreVert +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import com.boswelja.menuprovider.MenuItem + +/** + * Contains many "default case" [MenuItem]s used by the library. For example, the standard overflow + * MenuItem can be created here. + */ +public actual object DefaultMenuItems { + + /** + * Retrieves the "more options" [MenuItem]. This is used to present the user with a list of + * items when pressed, usually as a dropdown menu. + */ + @Composable + public actual fun moreOptions(onClick: () -> Unit): MenuItem = + MenuItem( + label = stringResource(R.string.menu_item_more), + imageVector = Icons.Default.MoreVert, + onClick = onClick, + isImportant = true + ) +} diff --git a/material3/src/androidMain/res/values/strings.xml b/material3/src/androidMain/res/values/strings.xml new file mode 100644 index 0000000..88a0026 --- /dev/null +++ b/material3/src/androidMain/res/values/strings.xml @@ -0,0 +1,4 @@ + + + More + \ No newline at end of file diff --git a/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt b/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt new file mode 100644 index 0000000..0564ce0 --- /dev/null +++ b/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/DefaultMenuItems.kt @@ -0,0 +1,18 @@ +package com.boswelja.menuprovider.material3 + +import androidx.compose.runtime.Composable +import com.boswelja.menuprovider.MenuItem + +/** + * Contains many "default case" [MenuItem]s used by the library. For example, the standard overflow + * MenuItem can be created here. + */ +public expect object DefaultMenuItems { + + /** + * Retrieves the "more options" [MenuItem]. This is used to present the user with a list of + * items when pressed, usually as a dropdown menu. + */ + @Composable + public fun moreOptions(onClick: () -> Unit): MenuItem +} diff --git a/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/TopAppBarMenuItems.kt b/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/TopAppBarMenuItems.kt index 981a09e..9aeba84 100644 --- a/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/TopAppBarMenuItems.kt +++ b/material3/src/commonMain/kotlin/com/boswelja/menuprovider/material3/TopAppBarMenuItems.kt @@ -20,6 +20,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import com.boswelja.menuprovider.AnimatedMenuItems import com.boswelja.menuprovider.LocalMenuHost import com.boswelja.menuprovider.MenuHost @@ -59,12 +60,10 @@ public fun TopAppBarMenuItems( var menuExpanded by rememberSaveable { mutableStateOf(false) } ExposedDropdownMenuBox(expanded = menuExpanded, onExpandedChange = { menuExpanded = !menuExpanded}) { TopAppBarAction( - menuItem = MenuItem( - label = "More", - imageVector = Icons.Default.MoreVert, - onClick = { menuExpanded = !menuExpanded }, - isImportant = false - ), + menuItem = DefaultMenuItems + .moreOptions { + menuExpanded = !menuExpanded + }, modifier = Modifier.menuAnchor() ) ExposedDropdownMenu(