diff --git a/compose/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopAlertDialog.desktop.kt b/compose/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopAlertDialog.desktop.kt index 56bd939ef95be..30d1539f0170b 100644 --- a/compose/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopAlertDialog.desktop.kt +++ b/compose/material/material/src/desktopMain/kotlin/androidx/compose/material/DesktopAlertDialog.desktop.kt @@ -46,6 +46,7 @@ import androidx.compose.ui.window.rememberDialogState import java.awt.event.KeyEvent import androidx.compose.ui.window.Dialog as CoreDialog import androidx.compose.foundation.background +import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.input.key.KeyEventType import androidx.compose.ui.input.key.type @@ -149,7 +150,10 @@ fun AlertDialog( dialogProvider: AlertDialogProvider = PopupAlertDialogProvider ) { with(dialogProvider) { - AlertDialog(onDismissRequest = onDismissRequest) { + AlertDialog( + onDismissRequest = onDismissRequest, + shape = shape, + ) { AlertDialogContent( buttons = buttons, modifier = modifier.width(IntrinsicSize.Min), @@ -174,10 +178,29 @@ interface AlertDialogProvider { * @param onDismissRequest Callback that will be called when the user closes the dialog * @param content Content of the dialog */ + @Deprecated("Will be removed in 1.5; use the overload that takes the dialog shape") + @Composable + fun AlertDialog( + onDismissRequest: () -> Unit, + content: @Composable () -> Unit + ) + + /** + * Dialog which will be used to place AlertDialog's [content]. + * + * @param onDismissRequest Callback that will be called when the user closes the dialog + * @param shape The Dialog's shape + * @param content Content of the dialog + */ + @Suppress("DEPRECATION") @Composable fun AlertDialog( onDismissRequest: () -> Unit, + shape: Shape, content: @Composable () -> Unit + ) = AlertDialog( + onDismissRequest = onDismissRequest, + content = content ) } @@ -188,10 +211,25 @@ interface AlertDialogProvider { */ @ExperimentalMaterialApi object PopupAlertDialogProvider : AlertDialogProvider { + + @Deprecated("Will be removed in 1.5; use the overload that takes the dialog shape") @Composable override fun AlertDialog( onDismissRequest: () -> Unit, content: @Composable () -> Unit + ) { + AlertDialog( + onDismissRequest = onDismissRequest, + shape = RectangleShape, + content = content + ) + } + + @Composable + override fun AlertDialog( + onDismissRequest: () -> Unit, + shape: Shape, + content: @Composable () -> Unit ) { // Popups on the desktop are by default embedded in the component in which // they are defined and aligned within its bounds. But an [AlertDialog] needs @@ -229,13 +267,18 @@ object PopupAlertDialogProvider : AlertDialogProvider { }, contentAlignment = Alignment.Center ) { - Surface(Modifier.pointerInput(onDismissRequest) { - detectTapGestures(onPress = { - // Workaround to disable clicks on Surface background https://github.com/JetBrains/compose-jb/issues/2581 - }) - }, elevation = 24.dp) { - content() - } + Surface( + modifier = Modifier.pointerInput(onDismissRequest) { + detectTapGestures(onPress = { + // Workaround to disable clicks on Surface background + // https://github.com/JetBrains/compose-jb/issues/2581 + }) + }, + shape = shape, + color = Color.Transparent, + elevation = 24.dp, + content = content + ) } } } @@ -246,6 +289,7 @@ object PopupAlertDialogProvider : AlertDialogProvider { */ @ExperimentalMaterialApi object UndecoratedWindowAlertDialogProvider : AlertDialogProvider { + @Deprecated("Will be removed in 1.5; use the overload that takes the dialog shape") @OptIn(ExperimentalComposeUiApi::class) @Composable override fun AlertDialog( @@ -256,6 +300,7 @@ object UndecoratedWindowAlertDialogProvider : AlertDialogProvider { onCloseRequest = onDismissRequest, state = rememberDialogState(width = Dp.Unspecified, height = Dp.Unspecified), undecorated = true, + transparent = true, resizable = false, onKeyEvent = { if (it.key == Key.Escape) {