Stylianos Gakis
03/24/2022, 1:44 PMLayout
, how it’s used in the implementation of Column|Row measure policy and in a codelab. More in thread 🧵layout
call, just like I can see it’s done in this codelab, in the code-snippet right above the “MyOwnColumn in action” section.
However then looking for this in cs.android I found this, which is the same snippet but with the y-coord being initialized inside the layout
block.
From my understanding that layout
block can be called independently from the rest and more than one time as , which makes me feel like you’d want to make these initializations be inside the block in which they are being used. Does it just not matter, or are some of these snippets slightly wrong or am I missing something?Albert Chang
03/24/2022, 2:08 PMmainAxisPositions
won’t be GCed after layout block is executed.Stylianos Gakis
03/24/2022, 2:15 PMlayout
block as 0 for example. But the layout
block is called twice, wouldn’t the old reference of yPosition still be referenced, which after the first layout
call was made it’d not be 0 anymore?
And if that’s not the case, how is it not the case? It just feels like a basic concept that both calls to it are referencing to the same mutable variable that is outside of their scope, which would mean that it might interfere with each other. I must be missing something, feeling kinda dumb even asking this, but what is it that I am missing?
Unless the layout
block isn’t just called separately from the rest of the code that’s above as I understood from the Deep dive into Jetpack Compose layouts
video that I linked in my comment above.Zach Klippenstein (he/him) [MOD]
03/24/2022, 3:27 PMStylianos Gakis
03/24/2022, 3:40 PMyPosition
isn’t written to first. It’s instead initialized outside of the `layout`’s placementBlock
and it’s then being read and written to inside the `layout`’s placementBlock
block.Zach Klippenstein (he/him) [MOD]
03/24/2022, 3:47 PMStylianos Gakis
03/24/2022, 3:50 PMlayout
block as I would suspect would be the correct way to do this. Since from the video I linked they imply that this block may be run independently, and I’d assume it would want to not use old references to a mutable variable that may have been mutated from a previous call to this block.
I am having a bit of a hard time to explain exactly what I am referring to considering there are so many things I am referring to, sorry for that, please point out if something still doesn’t make sense so that I can help clarifyAlbert Chang
03/24/2022, 4:17 PMStylianos Gakis
03/24/2022, 4:21 PMAlbert Chang
03/24/2022, 4:25 PMStylianos Gakis
03/24/2022, 4:46 PMAlbert Chang
03/25/2022, 2:00 AMLayout
being re-run so yPosition
is irrelevant here. The result of Layout
is cached and layout modifiers can’t access yPosition
.Stylianos Gakis
03/25/2022, 6:57 AMAlbert Chang
03/25/2022, 10:11 AMEven if there’s no state being read inside this layout doesn’t mean that just like in that video there could be some other modifier which does do that, making all the layout blocks to be re-run
Stylianos Gakis
03/25/2022, 12:35 PM