← Compose Multiplatform 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
name | description |
---|---|
onCloseRequest | Callback 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 = \{\} ) |
state | The 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. |
visible | Is [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. |
title | Title in the titlebar of the dialog |
icon | Icon 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) |
undecorated | Disables or enables decorations for this window. |
transparent | Disables or enables window transparency. Transparency should be set only if window is undecorated, otherwise an exception will be thrown. |
resizable | Can dialog be resized by the user (application still can resize the dialog changing [state]) |
enabled | Can dialog react to input events |
focusable | Can dialog receive focus |
alwaysOnTop | Should the dialog always be on top of another windows and dialogs |
onPreviewKeyEvent | This 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. |
onKeyEvent | This 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. |
content | content 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
name | description |
---|---|
visible | Is [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. |
onPreviewKeyEvent | This 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. |
onKeyEvent | This 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. |
create | The block creating the [ComposeDialog] to be composed. |
dispose | The block to dispose [ComposeDialog] and free native resources. Usually it is simple ComposeDialog::dispose |
update | The callback to be invoked after the layout is inflated. |
content | Composable 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
)