Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String-ify overflow item #30

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
)
}
4 changes: 4 additions & 0 deletions material3/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="menu_item_more">More</string>
</resources>
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.runtime.Composable
Expand All @@ -19,7 +17,6 @@ import androidx.compose.ui.Modifier
import com.boswelja.menuprovider.AnimatedMenuItems
import com.boswelja.menuprovider.LocalMenuHost
import com.boswelja.menuprovider.MenuHost
import com.boswelja.menuprovider.MenuItem

/**
* Takes the menu items provided to [menuHost] and displays them in such a way that is suitable for
Expand Down Expand Up @@ -55,12 +52,10 @@ public fun TopAppBarMenuItems(
var menuExpanded by rememberSaveable { mutableStateOf(false) }
ExposedDropdownMenuBox(expanded = menuExpanded, onExpandedChange = { menuExpanded = !menuExpanded}) {
IconButtonMenuItem(
menuItem = MenuItem(
label = "More",
imageVector = Icons.Default.MoreVert,
onClick = { menuExpanded = !menuExpanded },
isImportant = false
),
menuItem = DefaultMenuItems
.moreOptions {
menuExpanded = !menuExpanded
},
modifier = Modifier.menuAnchor()
)
ExposedDropdownMenu(
Expand Down