https://kotlinlang.org logo
Title
a

Adib Faramarzi

02/15/2022, 11:19 AM
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

Filip Wiesner

02/15/2022, 11:23 AM
There is no such thing as "rest of the screen" in scrollable layout. In scrollable column the height constraint is inifinite
a

Adib Faramarzi

02/15/2022, 11:23 AM
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

Filip Wiesner

02/15/2022, 11:25 AM
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

Adib Faramarzi

02/15/2022, 11:31 AM
Yes
I think some sort of layout modifier can be written
maybe, specifically for lazy column child
f

Filip Wiesner

02/15/2022, 11:32 AM
I still don't understand your use case so I can't help you 🤷‍♂️
a

Adib Faramarzi

02/15/2022, 11:35 AM
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

Filip Wiesner

02/15/2022, 11:38 AM
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

Adib Faramarzi

02/15/2022, 11:38 AM
yeah, it would be much easier with regular column and weight.
f

Filip Wiesner

02/15/2022, 11:39 AM
if (isEmpty) Column { ... } else LazyColumn { ... }
And reuse the same UI in both situations
a

Adib Faramarzi

02/15/2022, 11:39 AM
I'm trying to find a more efficient solution
Since this recomposes the top part
f

Filip Wiesner

02/15/2022, 11:42 AM
And does that actually change often? I thought you'll just display the screen with either empty content or with items.
z

Zoltan Demant

02/15/2022, 12:22 PM
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

Filip Wiesner

02/15/2022, 12:27 PM
That could work but it might be hard to do it "correctly" without things like
onGloballyPositioned()
. But that's your decision to make.
z

Zoltan Demant

02/15/2022, 12:36 PM
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

Filip Wiesner

02/15/2022, 12:38 PM
Well, slower UI is better than fragile UI in my book 🤷‍♂️
a

Afzal Najam

02/15/2022, 4:22 PM
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

Adib Faramarzi

02/15/2022, 4:24 PM
was not aware of that 👍
a

Andrey Kulikov

02/15/2022, 7:32 PM
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