:android-wave: Is there a way to measure a child b...
# compose
c
👋 Is there a way to measure a child before placing it and then fill the screen with the available amount of those children? Currently I'm creating a
Layout
for measurement of the child and then another
Layout
that will place X amount of those children based on screen height. The problem I ran into was each child I'm placing needs to be unique/not being currently laid out for the system to not give me
"Place was called on a node which was placed already"
.
z
I think
SubcomposeLayout
might be your best bet here. You basically described how the lazy lists work.
☝️ 1
You can use it to subcompose+measure the first child, then subcompose+etc as many other children as you need.
c
I thought about a
SubcomposeLayout
. Was sure that I would run into the same issue of not being able to place the same placeable. But now that I'm looking at it more calling
subcompose
would allow me to create a new placeable to place which should solve that. I'll try that next! Zach to the rescue again. 🦸
☝🏻 1
z
yep exactly, you can just call
subcompose
multiple times with the same content function
c
Sweet. That composable is so powerful
Now for the harder question of... which is better for performance? Having a
Layout
that gets the measure and is then removed from composition via a
mutableStateOf(Boolean)
+ a
Layout
to place. Or using
Subcomposelayout
Time to get out the profiler... 😱
z
Before even considering performance, those will do different things. The former will not show the content until the second frame, which will most likely look noticeably bad.
c
You don't really notice it, but yes you're right it would have to go through re-composition to show. Subcomposelayout seems to do the trick beautifully 🙂
z
There can be other negative effects of skipping that first frame (e.g. it breaks the IDE preview)
🤔 1
also yes 1