Jonathan
10/25/2024, 3:02 PMLazyRow
with a horizontal content padding of 16.dp
I'm unable to get children to fill the entire width of row occupies. The max width of children seem to be LazyRow.width
- contentPadding.horizontal
. I was hoping the content padding would act as an offset before the first and after the last child of the LazyRow
and not affect the max achievable width. Is the only solution to wrap my LazyRow
in a BoxWithContraints
in order to get the maxWidth
for the space the row occupies?Stylianos Gakis
10/25/2024, 3:03 PMcontentPadding: PaddingValues
, to do exactly what you describeStylianos Gakis
10/25/2024, 3:04 PMLazyRow() {
item { Spacer(Modifier.width(16.dp)) }
// whatever you had here before anyway
item { Spacer(Modifier.width(16.dp)) }
}
Stylianos Gakis
10/25/2024, 3:04 PMJonathan
10/25/2024, 3:04 PMLazyRow
Stylianos Gakis
10/25/2024, 3:06 PMJonathan
10/25/2024, 3:09 PMModifier.fillMaxParentWidth()
would size the child to be 200.dp
wide and not 200.dp
minus the 16.dp
left + 16.dp
right horizontal content padding.Stylianos Gakis
10/25/2024, 3:15 PMfillParentMaxWidth
, I see.
Then did you try with this approach?
LazyRow(contentPadding = PaddingValues(0.dp)) {
item { Spacer(Modifier.width(16.dp)) }
// whatever you had here before anyway
item { Spacer(Modifier.width(16.dp)) }
}
Your item in the middle should correctly match the size of your lazy row itself this wayStylianos Gakis
10/25/2024, 3:16 PMJonathan
10/25/2024, 3:17 PMArrangement.spacedBy(...)
my first and last items will have additional spacing otherwise I'd need to use custom per item {}
padding.Stylianos Gakis
10/25/2024, 3:19 PMLazyRow(
contentPadding = PaddingValues(0.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
) {
item { Spacer(Modifier.width(4.dp)) }
// whatever you had here before anyway
item { Spacer(Modifier.width(4.dp)) }
}
and it would all work out well. But I understand how this is not optimal.
You might want to file a report saying that you find it unexpected that Modifier.fillMaxParentWidth()
is shrunk by the contentPadding()
that you pass inside the LazyRow, and see what the maintainers of that have to say about it. Perhaps there's more people who think the same.Jonathan
10/25/2024, 3:23 PMJonathan
10/25/2024, 3:24 PMStylianos Gakis
10/25/2024, 3:25 PMitem{}
alternative and accept defeat, at least if it fits your needs 😄Jonathan
10/25/2024, 3:28 PMitem { Spacer(Modifier.width(…)) }
with item { Content(Modifier.padding(...)) }
is an ideal solution. I think maybe wrapping the LazyRow in a BoxWithConstraints
is far simplier.Stylianos Gakis
10/25/2024, 3:40 PMZach Klippenstein (he/him) [MOD]
10/25/2024, 4:35 PMJonathan
10/26/2024, 4:30 PMStylianos Gakis
10/26/2024, 5:11 PMZach Klippenstein (he/him) [MOD]
10/27/2024, 4:19 AMStylianos Gakis
10/27/2024, 7:57 AMZach Klippenstein (he/him) [MOD]
10/28/2024, 5:23 PMOr is that just not true for sub composition somehow?Yep. Subcomposition can happen during the measure or placement passes. This is part of what makes it so tricky, it totally upends all your assumptions about phase ordering.