I suspect this has been asked, not finding right a...
# compose
d
I suspect this has been asked, not finding right away. If I have
Copy code
Column
  Row { Text(); Text() }
  Row { Text(); Text() }
can I somehow make it so that it renders like this:
Copy code
text1:       hello
text2longer: world
especially if
Row
is some component defined in the different file. I tried to read about alignment lines, but can't see how they could help achieve this here.
f
If you want the first text to expand all the way you can use weight. If you want to use the width of the widest text instead, you should consider a Layout
This composable measures 2 views and makes them the same width, you could use this as a starting point https://github.com/fvilarino/Weather-Sample/blob/feature/compose/presentation/shar[…]ware/weathersample/presentation/shared/widget/EqualSizeTiles.kt
Note that for this you have to have access to all children at once so you can measure the widest one
d
Yep, I know I can do this with custom layout, but I wondered if this can be done without access to all children, if Rows are hidden in other components. Having a single layout here would break nice hierarchical structure. I.e. this
Copy code
Column {
  CustomRow()
  CustomRow()
}
is better for organization than this
Copy code
MyLayout {
   Text()
   Text()
   Text()
   Text()
}
f
That would require the rows to coordinate. This can only be done via the parent composable, as they have no visibility of one another.
c
Maybe I'm missing something, but wouldn't you just use weight here on both Text fields?
d
Alas, that would cause:
Copy code
text1:           |hello            |
text2longer:     |world            |
and also it might cut off
text2longer
if container is not wide enough
Still I thought that maybe there's some interesting solution, especially seeing how Alignment Lines can be sort-of cross-cutting solution which almost enable what I'd want. Perhaps if the position of an alignment line could be dynamically calculated depending on the largest text this would be doable, but I guess implementing this calculation will not be pretty and Layout would be a better way to go.
f
weight doesn't work because, if I understand the reqs correctly, we want to take the widest of the left texts and make them all that width
1
so each row needs to know how wide the left text of each other row is
that's why I believe this needs to be delegated to the parent of these rows, ether with a Layout or some other custom solution
c
@dimsuz weight has an additional arg called
fill
. Does that change anything?