Hi, I was wondering what does it mean when you cal...
# compose
a
Hi, I was wondering what does it mean when you call
subcompose(...)
inside
SubcomposeLayout(…)
? Is there a good source that dives deep into
SubcomposeLayout
? Thanks in advance.
👍 2
z
It causes the composable function you pass to it it to be composed, and any layout nodes it creates to be returned as measurables.
a
Hi @Zach Klippenstein (he/him) [MOD] Thanks! I’m still confuse though doesn’t
measurable.measure(constraint)
the one doing that? or am i completely misunderstanding it? 🤔
z
Nope,
measure
does the measuring. Compose UI has a number of stages: 1. Composition 2. Measuring 3. Layout (placement) 4. Drawing Typically, each of these stages happens, in order, completely, before the next stage begins. I.e. your entire UI is composed, which generates the tree of layout nodes. Then, all the layout nodes are measured. Then, all the nodes are placed/layed out. Then finally all the nodes are drawn in the correct places.
SubcomposeLayout
lets you bend the rules a bit, and reorder the first three steps for parts of your subtree.
In other words, by the time you have a
Measurable
, the code that created that
Measurable
has already been composed – it has to have been, you have to execute composable functions to generate `Measurable`s.
👍 1
a
So if I understand it correctly, by calling
subcompose(..)
the composable function I passed to it gets to be ahead and do, step 1, 2, and 3… ahead of the other composable functions? where normally, all composable function have to go through the steps at the same time? (Really appreciate the explanation, thank you very much)
z
subcompose
lets you perform step 1 for some subtree after measuring or even placing other layout nodes (which themselves may have been `subcompose`d later than usual)
it also lets you conditionally compose part of your tree – this is how `LazyList`s work
a
I see... I understand now... that is the reason why
BoxWithConstraint
have its constraints available to the content... hmm... last thing I am confuse is how:
it also lets you conditionally compose part of your tree – this is how `LazyList`s work
Is it becuase since I know how my parent's size, I could limit how much of the children must be composed, measured and layout?
z
Yes. A regular
Layout
lets you decide not to call
place
on certain nodes, which hides their content, but they are still being composed. With subcompose layout you can change what you actually compose on each pass (based on parent size or something else)
a
I see… thank you very much.. really appreciate it :)
s
Thank you! I needed an explaination as well 😊