# compose

Egor Trutenko

01/29/2020, 9:20 PM
Hi! Probably was already asked, but I'll try and duplicate: why do we need constraint layout in Compose? Isn't Compose layout system able to flatten complex nested hierarchies?

Zach Klippenstein (he/him) [MOD]

01/29/2020, 9:35 PM
Deep nesting is deep nesting – with `View`s, it is expensive because it creates a lot of expensive objects, but also because solving all those constraints recursively is expensive. Presumably the latter issue still affects Compose (still has to measure your composables). Additionally, some complex layouts are just ugly to try to express using simpler layouts. I believe this will also let you use MotionLayout features in Compose, or even animate by swapping `ConstraintSet`s.

Egor Trutenko

01/29/2020, 10:02 PM
I might be wrong, because I never really had deep dive into layout systems before, but there are layout systems which don't seem to suffer from this problem and solve it natively without additional tools like constraint layout. See Flutter, React, Yoga layout etc.
Also, MotionLayout is useless, fight me

Mihai Popa

01/29/2020, 10:30 PM
Compose should be able to handle deep layout hierarchies efficiently. However, some layouts can be expressed using ConstraintLayout more nicely


01/29/2020, 10:53 PM
@Egor Trutenko FYI React is not a layout system, it uses Flex Layout

Egor Trutenko

01/29/2020, 11:28 PM
@sngrekov as I said, I'm not really proficient with it. Thanks for clarification on what I meant
@Mihai Popa I'm a little suspicious as to whether implementing constraint layout in Compose is not a waste of time, considering there are a lot of other features to do and constraint, being only quality-of-life feature, might not be as important. Again, not assuming anything, just expressing my own concerns

Nicolas Roard

01/30/2020, 6:59 PM
As Mihai said, the main advantage is that there is a class of layouts that are more easily expressed with relative constraints than nested rows and columns (same reason why we had RelativeLayout in android 1.0). The other advantage is supporting MotionLayout -- though you may not care if you think it's useless 😄 (i'd definitely be interested to hear why you think it would be though)


01/30/2020, 11:16 PM
There are no tests nor documentation, should we just attempt to construct one? and diddle?

Nicolas Roard

01/31/2020, 3:33 AM
You can definitely play with it, but we are still exploring some ideas so so api may change (particularly for MotionLayout)
👍🏻 1