ComposeDialogs

More: Author   ReportBugs   
Tags:

Show compose Alert dialogs in seamlessly way, like you do with Snackbar

Single dialog with message:

val coroutineScope = rememberCoroutineScope()
val dialogState = rememberDialogState()

DialogScaffold(
    dialogState = dialogState,
) {
    ...
    coroutineScope.launch {
        val result = dialogState.show(
            title = "Hello",
            message = "Lorem ipsum dolor est",
            ok = "Accept",
            cancel = "Cancel"
        )
        when (result) {
            Action.Cancel -> "Cancel"
            Action.Ok -> "Ok"
            Dismissed -> "Dismissed"
            else -> "Unknown"
        }
    }
    ...
}

Dialog with selection items:

val coroutineScope = rememberCoroutineScope()
val dialogState = rememberDialogState()

DialogScaffold(
    dialogState = dialogState,
) {
    ...
    coroutineScope.launch {
        val forlayos = listOf(
            Forlayo("A"),
            Forlayo("B"),
            Forlayo("C"),
            Forlayo("D"),
        )
        val result = dialogState.showSingleChoice<Forlayo>(
            title = "Hello",
            items = forlayos,
            itemFormatter = { it.text },
            cancel = "Cancel"
        )

        currentStatus = when (result) {
            Action.Cancel -> "Cancel"
            Action.Ok -> "Ok"
            Dismissed -> "Dismissed"
            is ItemSelected<*> -> "Item selected: ${forlayos[result.which]}"
            else -> "Unknown"
        }
    }
    ...
}
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools