Compose poll! When you are implementing a complex ...
# compose
a
Compose poll! When you are implementing a complex layout that you can’t build with built-in layout primitives like
Row
and
Column
, what approach do you use the most? 1.
Modifier.onGloballyPositioned
/`Modifier.onPlaced` /
Modifier.onSizeChanged
2. Custom
Layout
3. Subcomposition (
BoxWithConstraints
, etc.)
3️⃣ 13
2️⃣ 36
1️⃣ 11
b
Does ConstraintLayout count as a primitive?
a
I think so - I’d also count
FlowRow
and
LazyVerticalGrid
as primitives. Complicated primitives, but not “custom”
👍 1
t
I don't see anything called ConstraintLayout
doesn't autocomplete, doesn't auto-import if I type it out in full
I really wish the inline docs would be useful
at the moment the most I get is the method signature
e
t
so how do we define a primitive then
if I can pull in another artifact and call that a primitive, I could do damn near anything
a
Agreed, if there’s a perfectly-made layout for your use case in a library then you could just use that. I’m mostly curious about what people reach for when they need something more complex, and they have to build that more complex thing directly
t
in Swing I was using GroupLayout and I am yet to find anything in Compose nearly as convenient as that
at some point I will probably try to implement that layout in Compose
I just have to get a good idea of what sort of API would look good
and Swing made a number of mistakes like making it very easy for people to hard-code lengths
e
I didn't think of #1 and #3 in terms of being general solutions for not being able to use a primitive layout. If anything, I think of them as being special cases of #2.
t
I often choose BoxWithConstraints as it's easier to grasp than customlayouts.
1
m
Usually I use
Modifier.onGloballyPositioned
and in some cases where performance matters I use
Layout
to avoid some recompositions.
s
For me: I have had to use onPlaced in scenarios where I want a composable to be scrollable, but for some reason I also want to know the size of it in the scrollable axis, so I have done the chain
.fillMaxHeight().onPlaced{save the height here to use somewhere else}.verticalScroll
in some places. Haven't used onGloballyPositioned anywhere yet, onPlaced has always been the thing that suited my needs when I reached for that. Haven't really used BoxWithConstraints I think. Layout for everything else.