Skip to content

Commit

Permalink
Create ExposedDropdownMenuItems
Browse files Browse the repository at this point in the history
  • Loading branch information
boswelja committed Dec 6, 2023
1 parent 0c4f406 commit ed089c1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.boswelja.menuprovider.material3

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.boswelja.menuprovider.LocalMenuHost
import com.boswelja.menuprovider.MenuHost
import com.boswelja.menuprovider.MenuItem

/**
* Displays a standard "overflow" button that, when pressed, reveals a dropdown menu containing all
* items provided by [menuHost].
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
public fun ExposedDropdownMenuItems(
expanded: Boolean,
onExpandedChange: () -> Unit,
modifier: Modifier = Modifier,
menuHost: MenuHost = LocalMenuHost.current,
dropdownItemContent: @Composable (MenuItem) -> Unit = { DropdownMenuItem(it) }
) {
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = { onExpandedChange() }
) {
IconButtonMenuItem(
menuItem = DefaultMenuItems
.moreOptions(onClick = onExpandedChange),
modifier = Modifier.menuAnchor().then(modifier)
)
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = onExpandedChange
) {
menuHost.menuItems.forEach {
dropdownItemContent(it)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public fun TopAppBarMenuItems(
}

var menuExpanded by rememberSaveable { mutableStateOf(false) }
ExposedDropdownMenuBox(expanded = menuExpanded, onExpandedChange = { menuExpanded = !menuExpanded}) {
ExposedDropdownMenuBox(expanded = menuExpanded, onExpandedChange = { menuExpanded = !menuExpanded }) {
IconButtonMenuItem(
menuItem = DefaultMenuItems
.moreOptions {
Expand Down

0 comments on commit ed089c1

Please sign in to comment.