commonMain.androidx.compose.ui.window.Dialog.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ui Show documentation
Show all versions of ui Show documentation
Compose UI primitives. This library contains the primitives that form the Compose UI Toolkit, such as drawing, measurement and layout.
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.compose.ui.window
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
/**
* Properties used to customize the behavior of a [Dialog].
*
* @property dismissOnBackPress whether the popup can be dismissed by pressing the back button
* * on Android or escape key on desktop.
* If true, pressing the back button will call onDismissRequest.
* @property dismissOnClickOutside whether the dialog can be dismissed by clicking outside the
* dialog's bounds. If true, clicking outside the dialog will call onDismissRequest.
* @property usePlatformDefaultWidth Whether the width of the dialog's content should be limited to
* the platform default, which is smaller than the screen width.
* **Might be used only as named argument**.
*/
@Immutable
expect class DialogProperties(
dismissOnBackPress: Boolean = true,
dismissOnClickOutside: Boolean = true,
usePlatformDefaultWidth: Boolean = true,
) {
val dismissOnBackPress: Boolean
val dismissOnClickOutside: Boolean
val usePlatformDefaultWidth: Boolean
}
/**
* Opens a dialog with the given content.
*
* A dialog is a small window that prompts the user to make a decision or enter
* additional information. A dialog does not fill the screen and is normally used
* for modal events that require users to take an action before they can proceed.
*
* The dialog is visible as long as it is part of the composition hierarchy.
* In order to let the user dismiss the Dialog, the implementation of [onDismissRequest] should
* contain a way to remove the dialog from the composition hierarchy.
*
* Example usage:
*
* @sample androidx.compose.ui.samples.DialogSample
*
* @param onDismissRequest Executes when the user tries to dismiss the dialog.
* @param properties [DialogProperties] for further customization of this dialog's behavior.
* @param content The content to be displayed inside the dialog.
*/
@Composable
expect fun Dialog(
onDismissRequest: () -> Unit,
properties: DialogProperties = DialogProperties(),
content: @Composable () -> Unit
)