https://kotlinlang.org logo
#compose
Title
# compose
m

Matej Drobnič

09/09/2021, 6:16 AM
Hello everybody. I have a more technical question regarding the layouting of compose. From documentation, compose has no double measuring. Instead, intrinsics are to be used. However, from what I see in the source code, by default, intrinsics just calls measure: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/MeasurePolicy.kt;l=138 What is the main difference then? Additionally, isn't that even worse than measuring? For example, if I want both max width and max height of some composable, before I do the final measure, I have to call both intrinsic methods, which will internally call measure twice, instead of just directly calling measure, which would give me both values in one call (but I'm not allowed to do that before final measure). Thanks.
After some digging, it appears that layouts like Column and Row define their own intrinsics
does that mean that flow will be significantly slower, since it will have to perform full measure for every intrinsic call?
a

Albert Chang

09/09/2021, 8:37 AM
if I want both max width and max height of some composable
Intrinsic size is the max/min width/height at a fixed height/width, respectively. Usually you just use one of the four intrinsic sizes. Why do you need both max width and max height?
since it will have to perform full measure for every intrinsic call
It's not full measure. Children that override intrinsic size methods (e.g.
Text
) can be measured faster.
m

Matej Drobnič

09/09/2021, 8:53 AM
I see
but if one were to implement, let's say, constraint layout, one would need both intrinsics, right?
to measure for all constraints
a

Albert Chang

09/09/2021, 9:24 AM
ConstraintLayout is the only MultiMeasureLayout. I don't think there's any layout you need to implement yourself using that.
m

Matej Drobnič

09/09/2021, 9:28 AM
I see
thanks for your answers
👍 1
12 Views