Mark
01/01/2024, 4:30 AM// in a Composable
var showItemSelectorDialog: ((Item?) -> Unit)? by remember {
mutableStateOf(null)
}
if (showItemSelectorDialog != null) {
ItemSelectorDialog(
onItemSelect = { item ->
showItemSelectorDialog?.invoke(item)
showItemSelectorDialog = null
},
)
}
// in some click handler
scope.launch {
viewModel.performSuspendingAction(
// depending on certain conditions, at some point the viewmodel may need to request an item choice from the user before continuing with the workflow
selectItem = {
suspendCancellableCoroutine { continuation ->
showItemSelectorDialog = { item ->
if (item == null) {
continuation.cancel()
} else {
continuation.resume(item)
}
}
}
},
)
}