Created
July 20, 2021 12:23
-
-
Save handstandsam/f1d83f7d554af6736d5fe2a6497bb98b to your computer and use it in GitHub Desktop.
Jetpack Compose Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun DropdownComposable(items: List<String> = listOf("A", "B", "C"), onClick: (String) -> Unit) { | |
var expanded by remember { mutableStateOf(false) } | |
var selectedIndex by remember { mutableStateOf(0) } | |
Box( | |
modifier = Modifier | |
.wrapContentSize(Alignment.TopStart) | |
) { | |
Text( | |
text = state.value.eventName, | |
modifier = Modifier | |
.fillMaxWidth() | |
.wrapContentHeight() | |
.clickable(onClick = { expanded = true }), | |
style = MaterialTheme.typography.body2 | |
) | |
DropdownMenu( | |
expanded = expanded, | |
onDismissRequest = { expanded = false }, | |
modifier = Modifier | |
.fillMaxWidth() | |
) { | |
items.forEachIndexed { index, s -> | |
DropdownMenuItem(onClick = { | |
selectedIndex = index | |
expanded = false | |
onClick(items[selectedIndex]) | |
}) { | |
Text(text = s) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment