https://kotlinlang.org logo
#compose
Title
# compose
s

Sergey Y.

10/19/2020, 10:14 AM
A weird issue happened to me after upgrading Compose to Alpha05. Text does not respect nor fillMaxWidth nor horizontalAlignment or Modifier.align for Column. It is always centered within the parent. Only when the text string is long enough Text spreads all parent width. Compose Alpha04 aligns text to the start of the Column as expected.
2
p

Philip Blandford

10/19/2020, 10:29 AM
I found the same thing - I've worked around it for now by putting the Text in a Box and aligning it that way
1
a

allan.conda

10/19/2020, 10:42 AM
s

Sergey Y.

10/19/2020, 11:13 AM
@Philip Blandford Funnily enough,
Modifier.weight (1.0f, fill = *false*)
fixes the problem. Looks like a workaround but not a solution.
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 1:38 PM
Does it work if you add
wrapContentWidth(Alignment.Start)
after the
fillMaxWidth()
modifier on your Text?
Also I think if you put the background modifier before the fillMaxWidth, you'll see that it is actuay filling the width, which is why the column's horizonalAlignment property isn't having any effect - as far as the column is concerned, there's nothing to align because the text already fills the available horizontal space. I am guessing maybe this changed in alpha05 because maybe how text measures itself with different flow modes changed? It seems like your text is ignoring the min width constraint, which is going to cause fillMaxWidth() to center it by default (I think). WrapContentWidth allows children to measure themselves as small as they want and will align inside constraints, so if they modifier fixes it that's probably what's going on.
Actually I think that's wrong, text might just be centering itself now? Does passing the
textAlign
property to Text fix it?
s

Sergey Y.

10/19/2020, 6:37 PM
textAlign
+
wrapContentWidth
did the trick
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 6:38 PM
wait, you still had to pass
textAlign
even though it’s
Start
by default?
s

Sergey Y.

10/19/2020, 6:39 PM
I was mistaken, null is default value
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 6:40 PM
ah
s

Sergey Y.

10/19/2020, 6:41 PM
but
textAlign
+
fillMaxWidth
looks broken to me.
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 6:43 PM
What are you expecting? It’s filling the max width, and the text is at the end, looks right to me
s

Sergey Y.

10/19/2020, 6:43 PM
First item is the same composable function
just with a shorter name
why is it centered instead of placed at the end
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 6:47 PM
Oh derp, of course. That definitely seems off. It almost seems like there’s an internal additional layout node that’s not being expanded?
s

Sergey Y.

10/19/2020, 6:49 PM
added another background to see text boundaries
modifier = Modifier.background(Color.Red).fillMaxWidth().background(Color.Blue),
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 6:53 PM
Do you get the same result if you remove the text overflow?
s

Sergey Y.

10/19/2020, 6:54 PM
Yes, text overflow has no effect to it
z

Zach Klippenstein (he/him) [MOD]

10/19/2020, 6:57 PM
I’d file a bug
Especially if this used to work in alpha04
s

Sergey Y.

10/19/2020, 6:59 PM
for sure, I will file a bug. Thanks.
a

allan.conda

10/20/2020, 2:30 AM
Have you created it yet? Looks like our Text that’s filling the width are centered as well 😆
4 Views