Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shape the surface behind an AlertDialog according to the dialog's shape. #424

Merged
merged 2 commits into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand All @@ -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
)
}

Expand All @@ -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
Expand Down Expand Up @@ -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
)
}
}
}
Expand All @@ -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(
Expand All @@ -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) {
Expand Down