Trying to build a simple color picker in an AlertD...
# compose
b
Trying to build a simple color picker in an AlertDialog. On some simple testings, the content (
text
) of the dialog is just
Copy code
Column
  Box // clipped to Circle
  Text
But with this ^ the content is being place over the dialog's title.
if i declare the Text before the Box, than it works
Copy code
Column
  Text
  Box
Here is the full AlertDialog declaration:
Copy code
AlertDialog(
        onDismissRequest = {
            onDismissRequest()
        },
        buttons = {
        },
        title = { Text("Select a color") },
        text = {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
                modifier = Modifier
                    .clickable {
                        onItemClick(myColors[0])
                    },
            ) {
                Box(
                    modifier = Modifier
                        .size(50.dp)
                        .clip(CircleShape)
                        .background(Color(myColors[0].rgbValue))
                )
                Text(myColors[0].name)
            }
        }
    )
(edited: formatting)
a
I am about to fall asleep right now so I cannot point you to a specific code right now but... Compose's AlertDialog has this annoying property that it tries to align the first baseline of
title
and the first baseline of
text
so that these baselines are always a fixed distance apart. No matter what you put before the first
Text()
within
text
you everything is offset based on that first
Text()
. IMO, this will break in so many cases where
text
is not just a simple message String. In our company, I've copy pasted the internal implementation and removed the code that was causing this.
👀 2
Try to put there a
TextField()
on the first place. I could not believe that is supposed to be expected behavior. The tile and contents will jump up and down as you focus and unfocus the first
TextField()
because the label is used as the first baseline of whole
text
.
Also the
AlertDialog
is broken that it does not update it's height when contents size changes. This can be reportedly fixed by passing some parameter via DialogParameters or something like usePlatformSize
b
Thanks for the detailed explanation
z
Have you reported this? Seems like a bug to me: in many cases it will behave unexpectedly.