Is there a way to have an `item` in a lazy column ...
# compose
a
Is there a way to have an
item
in a lazy column that fills the rest of the screen with its height? (
.fillMaxHeight
does not work).
f
There is no such thing as "rest of the screen" in scrollable layout. In scrollable column the height constraint is inifinite
a
What would be the solution for this then?
The height (the constrained height) is not infinite. That’s why the lazy column can recycle
f
It is inifnite because one item can span across multiple screen heights and is "recycled" when it leaves the visible part of column. The solution depends on your use case 😄
The height (the constrained height) is not infinite. That’s why the lazy column can recycle
I see, you meant the constraint of the column. I was talking about constraint of the item.
a
Yes
I think some sort of layout modifier can be written
maybe, specifically for lazy column child
f
I still don't understand your use case so I can't help you 🤷‍♂️
a
We’re having a page that includes two parts (one that fills about 200dp of the screen and one that has infinite amount of items) the second part can be empty and the design for the empty layout is a box that fills the rest of the screen and says “no items”.
and the whole page is scrollable (so all items are inside a lazy column)
The right one is what I’m talking about. The “no items” part is an
item
itself.
f
I guess that the most "easy to implement" way is to use
LazyColumn
only conditionally. Otherwise use normal column and use
weight(1f)
for the second element
a
yeah, it would be much easier with regular column and weight.
f
if (isEmpty) Column { ... } else LazyColumn { ... }
And reuse the same UI in both situations
a
I'm trying to find a more efficient solution
Since this recomposes the top part
f
And does that actually change often? I thought you'll just display the screen with either empty content or with items.
z
Couldnt you just calculate the first items height, and divide that by the lists total height, then use it with
Modifier.fillparentMaxHeight(fraction = 1f - firstItemHeightFraction)
. That should fill the rest of the screen, I think; just make sure the list has
Modifier.fillMaxSize
set so that youre actually getting its entire height in the calculation.
f
That could work but it might be hard to do it "correctly" without things like
onGloballyPositioned()
. But that's your decision to make.
z
Desperate times require desperate measures, @Filip Wiesner 🥲 It will also break if more than 1 item is "at the front"; but I cant think of any other solution for something like this.
f
Well, slower UI is better than fragile UI in my book 🤷‍♂️
a
Since this recomposes the top part
Don’t think that’d be a problem but even if it is,
moveableContentOf
in the latest alpha should alleviate that.
a
was not aware of that 👍
a
LazyColumn wraps the content height when there are not enough items to fill the maximum height. so you can wrap LazyColumn into one more Column and set weight on a second child, so it will fill the rest of the heigh not occupied by the LazyColumn
👍 1
👍🏽 1