Skip to content

SecurityDialog

SecurityDialog is a security statement dialog mirroring ColorOS's COUISecurityAlertDialogBuilder (coui_security_alert_dialog_statement_or_checkbox.xml): a regular alert dialog extended with a statement paragraph (with an optional tappable link), a "Don't remind me again" checkbox row and a cancel / confirm button bar of borderless accent-tinted text buttons.

Two variants are provided:

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

Prerequisite

OverlaySecurityDialog depends on Scaffold providing COUIPopupHost to render popup content. Use WindowSecurityDialog when no Scaffold is available.

Import

kotlin
import io.github.suqi8.coui.kmp.overlay.OverlaySecurityDialog
// or
import io.github.suqi8.coui.kmp.window.WindowSecurityDialog

import io.github.suqi8.coui.kmp.layout.SecurityDialogDefaults
import io.github.suqi8.coui.kmp.layout.SecurityDialogColors

Basic Usage

kotlin
var showDialog by remember { mutableStateOf(false) }

Scaffold {
    TextButton(
        text = "Show Security Dialog",
        onClick = { showDialog = true }
    )

    OverlaySecurityDialog(
        show = showDialog,
        title = "Security Notice",
        summary = "This feature needs to connect to the network.",
        statement = "Tap and view Privacy Policy for more information.",
        statementLinkText = "Privacy Policy",
        onLinkClick = { /* Open the privacy policy */ },
        onConfirm = { dontRemind ->
            showDialog = false
            if (dontRemind) { /* Persist the choice */ }
        },
        onCancel = { showDialog = false }
    )
}
  • The substring of statement equal to statementLinkText is rendered in the accent color and invokes onLinkClick when tapped.
  • Tapping outside and pressing back both invoke onCancel, matching COUI reporting the back key as the negative selection.
  • Passing checkboxText = null hides the checkbox row (equivalent to setHasCheckBox(false)).

Properties

OverlaySecurityDialog / WindowSecurityDialog Properties

Property NameTypeDescriptionDefault ValueRequired
showBooleanWhether to show the dialog-Yes
onConfirm(Boolean) -> UnitCalled on confirm with the current checkbox state-Yes
onCancel() -> UnitCalled on cancel button, outside tap, or back press-Yes
modifierModifierModifier applied to the dialogModifierNo
titleString?Dialog titlenullNo
summaryString?Dialog summary (message)nullNo
statementString?Statement paragraph; hidden when nullnullNo
statementLinkTextString?Substring of statement rendered as a tappable linknullNo
onLinkClick(() -> Unit)?Called when the statement link is tappednullNo
checkboxTextString?Checkbox row label; hidden when nullSecurityDialogDefaults.CheckboxTextNo
initialCheckedBooleanInitial checkbox state, re-applied each time the dialog is shownfalseNo
confirmTextStringConfirm (positive) button labelSecurityDialogDefaults.ConfirmTextNo
cancelTextStringCancel (negative) button labelSecurityDialogDefaults.CancelTextNo
titleColorColorTitle text colorDialogDefaults.titleColor()No
summaryColorColorSummary text colorDialogDefaults.summaryColor()No
backgroundColorColorDialog background colorDialogDefaults.backgroundColor()No
colorsSecurityDialogColorsColors of the statement, link and checkbox textsSecurityDialogDefaults.securityDialogColors()No
enableWindowDimBooleanWhether to enable dimming layertrueNo
onDismissFinished(() -> Unit)?Invoked after the hide animation completesnullNo
renderInRootScaffoldBooleanWhether to render the dialog in the root (outermost) Scaffold (OverlaySecurityDialog only)trueNo

SecurityDialogDefaults Object

Properties

Property NameTypeDescription
CheckboxTextStringDefault checkbox label ("Don't remind me again")
ConfirmTextStringDefault confirm button label ("OK")
CancelTextStringDefault cancel button label ("Cancel")

Functions

Function NameReturn TypeDescription
securityDialogColors()SecurityDialogColorsCreate the default statement / link / checkbox colors

SecurityDialogColors Properties

Property NameTypeDescription
statementColorColorStatement paragraph color (secondary label color)
linkColorColorInline link color (accent, 30% alpha while pressed)
checkboxTextColorColorCheckbox label color (secondary label color)

Advanced Usage

Without Statement or Checkbox

kotlin
OverlaySecurityDialog(
    show = showDialog,
    title = "Enable Feature",
    summary = "Do you want to enable this feature?",
    checkboxText = null, // Hide the checkbox row
    onConfirm = { _ -> showDialog = false },
    onCancel = { showDialog = false }
)

Custom Labels and Initial State

kotlin
OverlaySecurityDialog(
    show = showDialog,
    title = "Data Usage Reminder",
    statement = "See the User Agreement for details.",
    statementLinkText = "User Agreement",
    checkboxText = "Do not ask again",
    initialChecked = true,
    confirmText = "Agree",
    cancelText = "Disagree",
    onConfirm = { dontRemind -> showDialog = false },
    onCancel = { showDialog = false }
)

Changelog

Released under the Apache-2.0 License