Created
August 27, 2023 21:44
-
-
Save waseefakhtar/39296db3d4cd99abdc63025ac817e2d8 to your computer and use it in GitHub Desktop.
This file contains 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
@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