New Compose Multiplatform components arrived on Composables UICheck it out →

Component in Compose Ui

DialogWindow

Desktop

Composes platform dialog in the current composition. When Dialog enters the composition, a new platform dialog will be created and receives the focus. When Dialog leaves the composition, dialog will be disposed and closed.

Dialog is a modal window. It means it blocks the parent [Window] / [DialogWindow] in which composition context it was created.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.ui:ui:1.7.0-beta04")
}

Overloads

@Composable
fun DialogWindow(
    onCloseRequest: () -> Unit,
    state: DialogState = rememberDialogState(),
    visible: Boolean = true,
    title: String = "Untitled",
    icon: Painter? = null,
    undecorated: Boolean = false,
    transparent: Boolean = false,
    resizable: Boolean = true,
    enabled: Boolean = true,
    focusable: Boolean = true,
    alwaysOnTop: Boolean = false,
    onPreviewKeyEvent: ((KeyEvent) -> Boolean) = { false },
    onKeyEvent: ((KeyEvent) -> Boolean) = { false },
    content: @Composable DialogWindowScope.() -> Unit
)

Parameters

namedescription
onCloseRequestCallback that will be called when the user closes the dialog. Usually in this callback we need to manually tell Compose what to do: - change isOpen state of the dialog (which is manually defined) - close the whole application (onCloseRequest = ::exitApplication in [ApplicationScope]) - don't close the dialog on close request (onCloseRequest = \{\})
stateThe state object to be used to control or observe the dialog's state When size/position is changed by the user, state will be updated. When size/position of the dialog is changed by the application (changing state), the native dialog will update its corresponding properties. If [DialogState.position] is not [WindowPosition.isSpecified], then after the first show on the screen [DialogState.position] will be set to the absolute values.
visibleIs [DialogWindow] visible to user. If false: - internal state of [DialogWindow] is preserved and will be restored next time the dialog will be visible; - native resources will not be released. They will be released only when [DialogWindow] will leave the composition.
titleTitle in the titlebar of the dialog
iconIcon in the titlebar of the window (for platforms which support this). On macOs individual windows can't have a separate icon. To change the icon in the Dock, set it via iconFile in build.gradle (https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution#platform-specific-options)
undecoratedDisables or enables decorations for this window.
transparentDisables or enables window transparency. Transparency should be set only if window is undecorated, otherwise an exception will be thrown.
resizableCan dialog be resized by the user (application still can resize the dialog changing [state])
enabledCan dialog react to input events
focusableCan dialog receive focus
alwaysOnTopShould the dialog always be on top of another windows and dialogs
onPreviewKeyEventThis callback is invoked when the user interacts with the hardware keyboard. It gives ancestors of a focused component the chance to intercept a [KeyEvent]. Return true to stop propagation of this event. If you return false, the key event will be sent to this [onPreviewKeyEvent]'s child. If none of the children consume the event, it will be sent back up to the root using the onKeyEvent callback.
onKeyEventThis callback is invoked when the user interacts with the hardware keyboard. While implementing this callback, return true to stop propagation of this event. If you return false, the key event will be sent to this [onKeyEvent]'s parent.
contentcontent of the dialog
@Composable
@Suppress("unused"
@OptIn(ExperimentalComposeUiApi::class
fun DialogWindow(
    visible: Boolean = true,
    onPreviewKeyEvent: ((KeyEvent) -> Boolean) = { false },
    onKeyEvent: ((KeyEvent) -> Boolean) = { false },
    create: () -> ComposeDialog,
    dispose: (ComposeDialog) -> Unit,
    update: (ComposeDialog) -> Unit = {},
    content: @Composable DialogWindowScope.() -> Unit
)

Parameters

namedescription
visibleIs [ComposeDialog] visible to user. If false: - internal state of [ComposeDialog] is preserved and will be restored next time the dialog will be visible; - native resources will not be released. They will be released only when [DialogWindow] will leave the composition.
onPreviewKeyEventThis callback is invoked when the user interacts with the hardware keyboard. It gives ancestors of a focused component the chance to intercept a [KeyEvent]. Return true to stop propagation of this event. If you return false, the key event will be sent to this [onPreviewKeyEvent]'s child. If none of the children consume the event, it will be sent back up to the root using the onKeyEvent callback.
onKeyEventThis callback is invoked when the user interacts with the hardware keyboard. While implementing this callback, return true to stop propagation of this event. If you return false, the key event will be sent to this [onKeyEvent]'s parent.
createThe block creating the [ComposeDialog] to be composed.
disposeThe block to dispose [ComposeDialog] and free native resources. Usually it is simple ComposeDialog::dispose
updateThe callback to be invoked after the layout is inflated.
contentComposable content of the creating dialog.
@Composable
@Deprecated(
    level = DeprecationLevel.HIDDEN,
    message = "Replaced by an overload that also takes alwaysOnTop",

fun DialogWindow(
    onCloseRequest: () -> Unit,
    state: DialogState = rememberDialogState(),
    visible: Boolean = true,
    title: String = "Untitled",
    icon: Painter? = null,
    undecorated: Boolean = false,
    transparent: Boolean = false,
    resizable: Boolean = true,
    enabled: Boolean = true,
    focusable: Boolean = true,
    onPreviewKeyEvent: ((KeyEvent) -> Boolean) = { false },
    onKeyEvent: ((KeyEvent) -> Boolean) = { false },
    content: @Composable DialogWindowScope.() -> Unit
)