Skip to content

LoadingDialog

LoadingDialog is a small always-centered dialog card with a rotating spinner and an optional message, mirroring ColorOS's rotating progress dialog (COUIRotatingDialogBuilder / coui_progress_dialog_rotating.xml): a 152dp-wide card with a 9dp corner radius, a 26dp spinner and 14sp label text.

Two variants are provided:

  • OverlayLoadingDialog — rendered inside Scaffold's COUIPopupHost (must be used within Scaffold).
  • WindowLoadingDialog — rendered at window level, no Scaffold required.

Prerequisite

OverlayLoadingDialog depends on Scaffold providing COUIPopupHost to render popup content. Use WindowLoadingDialog when no Scaffold is available.

Import

kotlin
import io.github.suqi8.coui.kmp.overlay.OverlayLoadingDialog
// or
import io.github.suqi8.coui.kmp.window.WindowLoadingDialog

import io.github.suqi8.coui.kmp.layout.LoadingDialogDefaults

Basic Usage

kotlin
var showLoading by remember { mutableStateOf(false) }

Scaffold {
    TextButton(
        text = "Start Loading",
        onClick = { showLoading = true }
    )

    OverlayLoadingDialog(
        show = showLoading,
        text = "Loading..."
    )

    // Hide the dialog when the task completes
    LaunchedEffect(showLoading) {
        if (showLoading) {
            doWork()
            showLoading = false
        }
    }
}

Without a message the spinner simply centers inside the card:

kotlin
OverlayLoadingDialog(show = showLoading)

WindowLoadingDialog is used the same way, but renders in a platform window and needs no Scaffold:

kotlin
var showLoading by remember { mutableStateOf(false) }

WindowLoadingDialog(
    show = showLoading,
    text = "Loading..."
)

User Dismissal

By default the dialog cannot be dismissed by the user, matching a non-cancelable COUI progress dialog. Pass onDismissRequest to allow dismissal by tapping outside or pressing back:

kotlin
OverlayLoadingDialog(
    show = showLoading,
    text = "Loading...",
    onDismissRequest = { showLoading = false }
)

Properties

OverlayLoadingDialog Properties

Property NameTypeDescriptionDefault ValueRequired
showBooleanWhether to show the dialog-Yes
modifierModifierModifier applied to the dialogModifierNo
textString?Message shown below the spinnernullNo
textColorColorMessage text colorLoadingDialogDefaults.textColor()No
spinnerColorColorSpinner colorLoadingDialogDefaults.spinnerColor()No
backgroundColorColorCard background colorDialogDefaults.backgroundColor()No
enableWindowDimBooleanWhether to enable dimming layertrueNo
onDismissRequest(() -> Unit)?Called when the user taps outside or presses back; when null the dialog cannot be dismissednullNo
onDismissFinished(() -> Unit)?Invoked after the hide animation completesnullNo
renderInRootScaffoldBooleanWhether to render the dialog in the root (outermost) Scaffold. When true, the dialog covers the full screen. When false, it renders within the current Scaffold's boundstrueNo

WindowLoadingDialog Properties

Same as OverlayLoadingDialog, without renderInRootScaffold (the dialog always renders at window level):

Property NameTypeDescriptionDefault ValueRequired
showBooleanWhether to show the dialog-Yes
modifierModifierModifier applied to the dialogModifierNo
textString?Message shown below the spinnernullNo
textColorColorMessage text colorLoadingDialogDefaults.textColor()No
spinnerColorColorSpinner colorLoadingDialogDefaults.spinnerColor()No
backgroundColorColorCard background colorDialogDefaults.backgroundColor()No
enableWindowDimBooleanWhether to enable dimming layertrueNo
onDismissRequest(() -> Unit)?Called when the user taps outside or presses back; when null the dialog cannot be dismissednullNo
onDismissFinished(() -> Unit)?Invoked after the hide animation completesnullNo

LoadingDialogDefaults Object

Properties

Property NameTypeDescription
CardWidthDpCard width, COUI coui_spinner_layout_width (152.dp)
CardMinHeightDpMinimum card height, COUI coui_spinner_layout_min_height (120.dp)
CornerRadiusDpCard corner radius, COUI couiRoundCornerMRadius (9.dp)
SpinnerSizeDpSpinner diameter, COUI coui_spinner_loading_anim_width (26.dp)

Functions

Function NameReturn TypeDescription
textColor()ColorDefault message color (primary label color)
spinnerColor()ColorDefault spinner color (primary label color)

Changelog

Released under the Apache-2.0 License