-
Notifications
You must be signed in to change notification settings - Fork 81
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
Alert dialog to match the maximum of the width of its content #433
Conversation
This PR is a lot of words for a 2-character change in the source :-) |
Maybe dialogs could have a default width set, and the developer can override that default if it doesn't work? |
@m-sasha Are you trying to run |
I haven't, but I will now. |
Maybe, but that requires a decision, and decisions are hard 😉 |
...rial/material/src/desktopMain/kotlin/androidx/compose/material/DesktopAlertDialog.desktop.kt
Show resolved
Hide resolved
Added default padding of |
351359d
to
aa51fc1
Compare
aa51fc1
to
0b03916
Compare
The problem here is the
modifier.width(IntrinsicSize.Min)
we pass toAlertDialogContent
, asking it to size itself to the minimum width it can. This causes (at least) two problems:Modifier.widthIn
on theAlertDialog
doesn't do anything, but it seems like a reasonable way to control the width of a dialog on the desktop.Ideally, we shouldn't be trying to control the width at all (which would also get rid of the crash when you put lazy content in an
AlertDialog
), but the problem with that is with thefillMaxWidth()
here:Without controlling the width outside of that, it will cause the dialog to always take the maximum available horizontal space.
But without the
fillMaxWidth
it's hard to position theAlertDialogFlowRow
correctly because we can neither pass amodifier
toAlertDialogFlowRow
nor control its alignment inside theColumn
inAlertDialogContent
.Note that all the discussion below applies to the case when the user doesn't specify a width on the
AlertDialog
.There are two possible solutions I see:
IntrinsicSize.Max
instead ofIntrinsicSize.Min
AlertDialogFlowRow
in, and don't specify any width on theAlertDialogContent
.Pros of 1:
The dialog would be sized to the content's maximum preferred width, but not wider. With the 2nd solution, it would always take the width of the entire window.
Pros of 2:
Using lazy content would not crash (although we said using lazy content in an
AlertDialog
is not a valid use-case). With the 1st solution, it would continue crashing.Note that both solutions would change the existing (I would argue wrong) behavior which, if there are buttons present and the user didn't specify a width, would use the width of the buttons for the size of the dialog (because their minimum width is larger than the minimum width of the text). So before, it would look like this:
and after the change:
But note that this is only if the user doesn't specify a width (or
widthIn
) himself.Proposed Changes
This PR goes with the simpler solution of using
IntrinsicSize.Max
. I think the benefit of sizing to the preferred content width is more important that allowing lazy content.Testing
Test: Manual testing with code like this:
Issues Fixed
Fixes: JetBrains/compose-multiplatform#2836