Last active
October 16, 2020 08:49
-
-
Save rooparsh/d9047e1820ee891eff7d278bf9c7dc56 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
@Composable | |
fun SingleSelectDialog(title: String, | |
optionsList: List<String>, | |
defaultSelected: Int, | |
submitButtonText: String, | |
onSubmitButtonClick: (Int) -> Unit, | |
onDismissRequest: () -> Unit) { | |
val selectedOption = mutableStateOf(defaultSelected) | |
Dialog(onDismissRequest = { onDismissRequest.invoke() }) { | |
Surface(modifier = Modifier.preferredWidth(300.dp), | |
shape = RoundedCornerShape(10.dp)) { | |
Column(modifier = Modifier.padding(10.dp)) { | |
Text(text = title) | |
Spacer(modifier = Modifier.preferredHeight(10.dp)) | |
LazyColumnFor(items = optionsList, modifier = Modifier.preferredHeight(500.dp)) { | |
RadioButton(it, optionsList[selectedOption.value]) { selectedValue -> | |
selectedOption.value = optionsList.indexOf(selectedValue) | |
} | |
} | |
Spacer(modifier = Modifier.preferredHeight(10.dp)) | |
Button(onClick = { | |
onSubmitButtonClick.invoke(selectedOption.value) | |
onDismissRequest.invoke() | |
}, | |
shape = MaterialTheme.shapes.medium) { | |
Text(text = submitButtonText) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment