Skip to content

Instantly share code, notes, and snippets.

@waseefakhtar
Created August 27, 2023 21:44
Show Gist options
  • Save waseefakhtar/39296db3d4cd99abdc63025ac817e2d8 to your computer and use it in GitHub Desktop.
Save waseefakhtar/39296db3d4cd99abdc63025ac817e2d8 to your computer and use it in GitHub Desktop.
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun RecurrenceDropdownMenu(recurrence: (String) -> Unit) {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = stringResource(id = R.string.recurrence),
style = MaterialTheme.typography.bodyLarge
)
val options = getRecurrenceList().map { it.name }
var expanded by remember { mutableStateOf(false) }
var selectedOptionText by remember { mutableStateOf(options[0]) }
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = { expanded = !expanded },
) {
TextField(
modifier = Modifier.menuAnchor(),
readOnly = true,
value = selectedOptionText,
onValueChange = {},
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
colors = ExposedDropdownMenuDefaults.textFieldColors(),
)
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false },
) {
options.forEach { selectionOption ->
DropdownMenuItem(
text = { Text(selectionOption) },
onClick = {
selectedOptionText = selectionOption
recurrence(selectionOption)
expanded = false
}
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment