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

Conversation

m-sasha
Copy link

@m-sasha m-sasha commented Mar 6, 2023

Proposed Changes

  • Pass the shape defining the AlertDialog to the AlertDialogProvider.
  • Change PopupAlertDialogProvider to pass the shape to the Surface that displays the elevation shadow, in order to draw the shadow with the correct shape.
  • Change PopupAlertDialogProvider to use a transparent background for the Surface that displays the elevation shadow. Otherwise the edges of its background can still show through the dialog content's shape.
    AlertDialogContent uses its own Surface at the root, so unless the user passes a translucent backgroundColor to AlertDialog, this change should not be visible.
  • Likewise change UndecoratedWindowAlertDialogProvider to use CoreDialog(transparent=true).

Note that this adds a new function to the (public) AlertDialogProvider interface, but the new function has a default implementation that delegates to the old function. I think this provides backwards compatibility.

Reproducer:

@OptIn(ExperimentalMaterialApi::class)
fun main() = singleWindowApplication(
    state = WindowState(width = 300.dp, height = 300.dp)
) {
    Box{
        MaterialTheme {
            AlertDialog(
                onDismissRequest = { },
                buttons = {},
                text = { Text("AlertDialog") },
                shape = RoundedCornerShape(20.dp),
                backgroundColor = Color.Yellow,
            )
        }
    }
}

Before:

image

After:

image

Testing

Test: Manual testing using the code above.

Issues Fixed

Fixes: JetBrains/compose-multiplatform#1269

@m-sasha m-sasha merged commit 22b4b01 into jb-main Mar 9, 2023
@m-sasha m-sasha deleted the shaped-alert-dialog branch March 9, 2023 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants