Is there a way to get `FlowRow` to apply `SpaceBet...
# compose
m
Is there a way to get
FlowRow
to apply
SpaceBetween
on all rows except the last one? Ideally there would be an extra optional arg:
Copy code
lastRowHorizontalArrangement: Arrangement.Horizontal = horizontalArrangement,
đźš« 1
o
I think best way is to write your own arrangement. It’s pretty straightforward.
m
Yeah, I guess so. However, I think it should be built-in to
FlowRow
because
SpaceBetween
looks pretty terrible when the last row only has a couple of a items and the
FlowRow
is rather wide. It should be possible to look like normal justified text.
o
Uhm, can you give an example of what it looks like and what do you want from it?
m
I think the only way to describe it is I want the items to be laid out like “justified” text - i.e.
SpaceBetween
except for the last row, which would be
Start
. I can’t think of too many cases where it would look good to have the last row with one item on each edge with a large space in between. If you wanted to keep symmetry, then
Center
would work for the last row. I suppose this could potentially happen on any row (if next item is very wide), and that’s why we have hyphenation in text. But in most cases, when we are using
SpaceBetween
we are doing so with relatively narrow items because we understand this. Thinking more about this, what you really want is a way for the
FlowRow
content to indicate to
FlowRow
to start a new row (and at the same time indicate which
horizontalArrangement
to apply to that latest row). Analogy here is when there is a line break in text.
o
Just to make sure, you mean
FlowRow
from accompanist?
m
No
androidx.compose.foundation.layout.FlowRow
o
I see, looked in the sources and I don’t see any way for you to have what you want. I was wrong, you can’t write your own arrangement to get it. I believe it is clearly missed case to be able to layout things as justified-except-last-row, unless I’m not seeing something obvious there. Also, I don’t think altering API of
FlowRow
would be a proper way to fix it. Instead, I’d extend API of
Arrangements
. Thinking out loud, one way to do it would be to introduce
Table
(name TBD) interface inside
Arrangement
object, that would have an additional function
arrange2D
(or just an overload for
arrange
) to indicate 2D layouts:
Copy code
fun Density.arrange2D(
            totalSize: Int,
            sizes: IntArray,
            layoutDirection: LayoutDirection,
            outPositions: IntArray,
            sliceIndex: Int, // current column/row 
            totalSlices: Int // total columns/rows
        )
That would make it possible for arrangement to decide on first/last/whatever row/column.
FlowRow
and related code would do something like
arrangement2D = (arrangement as? Table) ?: wrapTable(arrangement)
where
wrapTable
would provide Table API and just ignore extra parameters. Then two-dimensional layouts, like `FlowRow`/`FlowColumn`, grids, etc would feed Table arrangement with the current index of row/column and total number of those.
j
Please file an issue for us to look at:)
j
Thanks, I'll route it to our layouts person!
204 Views