Chris Fillmore
09/14/2022, 8:42 PMDropdownMenu
when it is clicked? Is the only way through DropdownMenuItem
via its onClick
?
I’ve tried passing DropdownMenu(modifier = Modifier.clickable …)
but this doesn’t have any effect that I can see.Chris Fillmore
09/14/2022, 8:45 PMDropdownMenuItem
Alex Vanyo
09/14/2022, 8:48 PMexpanded
parameter passed to DropdownMenu
.
For the simplest case, you probably want to have onDismissRequest
and item clicks update a state that results in DropdownMenu(expanded = false)
Chris Fillmore
09/14/2022, 8:55 PMvar expanded by remember { mutableStateOf(false) }
// There is a clickable icon with onClick = { expanded = true }
DropdownMenu(expanded = expanded, ...) {
DropdownMenuItem(
onClick = {
expanded = false
onSelectAllClick()
}
) {
Text("Select All")
}
DropdownMenuItem(
onClick = {
expanded = false
onSelectNoneClick()
}
) {
Text("Select None")
}
DropdownMenuItem(
onClick = {
expanded = false
onRefreshListClick()
}
) {
Text("Refresh List")
}
}
Chris Fillmore
09/14/2022, 8:57 PMDropdownMenuItem
onClick
handlers must dismiss the DropdownMenu
Chris Fillmore
09/14/2022, 8:57 PMChris Fillmore
09/14/2022, 9:01 PMlistOf(selectAll, selectNone, refreshList).forEach { menuItem ->
DropdownMenuItem(...)
}
Tbh it seems overkill for such a simple menu. But I’d be curious to know what is idiomatic hereAlex Vanyo
09/14/2022, 9:37 PMhideMenuAnd(lambda: () -> Unit)
.
But agreed, I think that’s still pretty overkill. I think what you originally have is straightforward. It might be a bit more verbose, but it’s crystal clear what’s going on.Chris Fillmore
09/15/2022, 2:01 PMhideMenuAnd
lambda as you suggest.