Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit affdc39

Browse files
authored
Fix issue with optimization (#186)
also allows passing the optimization level to ConstraintLayout
1 parent 2a8adf1 commit affdc39

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

constraintlayout/compose/src/main/java/androidx/constraintlayout/compose/ConstraintLayout.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.Measure.USE_
6464
@Composable
6565
fun ConstraintLayout(
6666
modifier: Modifier = Modifier,
67+
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
6768
content: @Composable ConstraintLayoutScope.() -> Unit
6869
) {
6970
val measurer = remember { Measurer() }
@@ -100,6 +101,7 @@ fun ConstraintLayout(
100101
layoutDirection,
101102
constraintSet,
102103
measurables,
104+
optimizationLevel,
103105
this
104106
)
105107
layout(layoutSize.width, layoutSize.height) {
@@ -118,6 +120,7 @@ fun ConstraintLayout(
118120
fun ConstraintLayout(
119121
constraintSet: ConstraintSet,
120122
modifier: Modifier = Modifier,
123+
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
121124
content: @Composable () -> Unit
122125
) {
123126
val measurer = remember { Measurer() }
@@ -131,6 +134,7 @@ fun ConstraintLayout(
131134
layoutDirection,
132135
constraintSet,
133136
measurables,
137+
optimizationLevel,
134138
this
135139
)
136140
layout(layoutSize.width, layoutSize.height) {
@@ -1291,12 +1295,12 @@ private class Measurer : BasicMeasure.Measurer {
12911295
Log.d("CCL2", "DW ${matchConstraintDefaultDimension}")
12921296
Log.d("CCL2", "ODR ${otherDimensionResolved}")
12931297
Log.d("CCL2", "IRH ${currentDimensionResolved}")
1294-
val useDimension = (measureStrategy == TRY_GIVEN_DIMENSIONS ||
1298+
val useDimension = currentDimensionResolved ||
1299+
(measureStrategy == TRY_GIVEN_DIMENSIONS ||
12951300
measureStrategy == USE_GIVEN_DIMENSIONS) &&
12961301
(measureStrategy == USE_GIVEN_DIMENSIONS ||
12971302
matchConstraintDefaultDimension != MATCH_CONSTRAINT_WRAP ||
1298-
otherDimensionResolved ||
1299-
currentDimensionResolved)
1303+
otherDimensionResolved)
13001304
Log.d("CCL", "UD $useDimension")
13011305
outConstraints[0] = if (useDimension) dimension else 0
13021306
outConstraints[1] = if (useDimension) dimension else rootMaxConstraint
@@ -1318,6 +1322,7 @@ private class Measurer : BasicMeasure.Measurer {
13181322
layoutDirection: LayoutDirection,
13191323
constraintSet: ConstraintSet,
13201324
measurables: List<Measurable>,
1325+
optimizationLevel: Int,
13211326
measureScope: MeasureScope
13221327
): IntSize {
13231328
this.density = measureScope
@@ -1361,7 +1366,7 @@ private class Measurer : BasicMeasure.Measurer {
13611366
}
13621367

13631368
// No need to set sizes and size modes as we passed them to the state above.
1364-
root.optimizationLevel = Optimizer.OPTIMIZATION_STANDARD
1369+
root.optimizationLevel = optimizationLevel //Optimizer.OPTIMIZATION_STANDARD
13651370
root.measure(root.optimizationLevel, 0, 0, 0, 0, 0, 0, 0, 0)
13661371

13671372
for (child in root.children) {

0 commit comments

Comments
 (0)