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

Commit c4e3472

Browse files
committed
[Compose] Refactor out MotionLayout.kt classes
This refactors the following classes into separate files (with their respective interfaces, helper functions): - Transition.kt: Transition, (Composable) Transition, TransitionImpl - MotionScene.kt: MotionScene, (Composable) MotionScene, JSONMotionScene - MotionMeasurer.kt: MotionMeasurer Applied formatting rest of package
1 parent eb5afdd commit c4e3472

File tree

8 files changed

+775
-719
lines changed

8 files changed

+775
-719
lines changed

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

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ private class ConstraintLayoutParentData(
481481
override val layoutId: Any = ref.id
482482

483483
override fun equals(other: Any?) = other is ConstraintLayoutParentData &&
484-
ref.id == other.ref.id && constrain == other.constrain
484+
ref.id == other.ref.id && constrain == other.constrain
485485

486486
override fun hashCode() = ref.id.hashCode() * 31 + constrain.hashCode()
487487
}
@@ -722,7 +722,7 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
722722
private var forcedWidth: Int = Int.MIN_VALUE
723723
private var forcedHeight: Int = Int.MIN_VALUE
724724
private var forcedDrawDebug: MotionLayoutDebugFlags =
725-
MotionLayoutDebugFlags.UNKNOWN
725+
MotionLayoutDebugFlags.UNKNOWN
726726
private var updateFlag: MutableState<Long>? = null
727727
private var layoutInformationMode: LayoutInfoFlags = LayoutInfoFlags.NONE
728728
private var layoutInformation = ""
@@ -774,7 +774,8 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
774774
val registry = Registry.getInstance()
775775
registry.register(debugName, callback)
776776
}
777-
} catch (_: CLParsingException) {}
777+
} catch (_: CLParsingException) {
778+
}
778779
}
779780

780781
// region Accessors
@@ -931,6 +932,7 @@ fun ConstraintSet(
931932
class State(val density: Density) : SolverState() {
932933
var rootIncomingConstraints: Constraints = Constraints()
933934
lateinit var layoutDirection: LayoutDirection
935+
934936
init {
935937
setDpToPixel { dp -> density.density * dp }
936938
}
@@ -996,7 +998,7 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
996998
Log.d(
997999
"CCL",
9981000
"Measuring ${measurable.layoutId} with: " +
999-
constraintWidget.toDebugString() + "\n" + measure.toDebugString()
1001+
constraintWidget.toDebugString() + "\n"
10001002
)
10011003
}
10021004

@@ -1033,11 +1035,11 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
10331035
}
10341036

10351037
if ((measure.measureStrategy == TRY_GIVEN_DIMENSIONS ||
1036-
measure.measureStrategy == USE_GIVEN_DIMENSIONS) ||
1038+
measure.measureStrategy == USE_GIVEN_DIMENSIONS) ||
10371039
!(measure.horizontalBehavior == MATCH_CONSTRAINT &&
1038-
constraintWidget.mMatchConstraintDefaultWidth == MATCH_CONSTRAINT_SPREAD &&
1039-
measure.verticalBehavior == MATCH_CONSTRAINT &&
1040-
constraintWidget.mMatchConstraintDefaultHeight == MATCH_CONSTRAINT_SPREAD)
1040+
constraintWidget.mMatchConstraintDefaultWidth == MATCH_CONSTRAINT_SPREAD &&
1041+
measure.verticalBehavior == MATCH_CONSTRAINT &&
1042+
constraintWidget.mMatchConstraintDefaultHeight == MATCH_CONSTRAINT_SPREAD)
10411043
) {
10421044
if (DEBUG) {
10431045
Log.d("CCL", "Measuring ${measurable.layoutId} with $constraints")
@@ -1103,7 +1105,7 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
11031105
.copyFrom(measure)
11041106

11051107
measure.measuredNeedsSolverPass = measure.measuredWidth != measure.horizontalDimension ||
1106-
measure.measuredHeight != measure.verticalDimension
1108+
measure.measuredHeight != measure.verticalDimension
11071109
}
11081110

11091111
fun addLayoutInformationReceiver(layoutReceiver: LayoutInformationReceiver?) {
@@ -1134,8 +1136,8 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
11341136
json.append(" interpolated: ")
11351137
json.append(
11361138
" { left: ${child.x}, top: ${child.y}, " +
1137-
"right: ${child.x + child.width}, " +
1138-
"bottom: ${child.y + child.height} }"
1139+
"right: ${child.x + child.width}, " +
1140+
"bottom: ${child.y + child.height} }"
11391141
)
11401142
json.append("}, ")
11411143
}
@@ -1192,11 +1194,11 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
11921194
Log.d("CCL", "IRH $currentDimensionResolved")
11931195
}
11941196
val useDimension = currentDimensionResolved ||
1195-
(measureStrategy == TRY_GIVEN_DIMENSIONS ||
1196-
measureStrategy == USE_GIVEN_DIMENSIONS) &&
1197-
(measureStrategy == USE_GIVEN_DIMENSIONS ||
1198-
matchConstraintDefaultDimension != MATCH_CONSTRAINT_WRAP ||
1199-
otherDimensionResolved)
1197+
(measureStrategy == TRY_GIVEN_DIMENSIONS ||
1198+
measureStrategy == USE_GIVEN_DIMENSIONS) &&
1199+
(measureStrategy == USE_GIVEN_DIMENSIONS ||
1200+
matchConstraintDefaultDimension != MATCH_CONSTRAINT_WRAP ||
1201+
otherDimensionResolved)
12001202
if (DEBUG) {
12011203
Log.d("CCL", "UD $useDimension")
12021204
}
@@ -1288,7 +1290,7 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
12881290
Log.d(
12891291
"CCL",
12901292
"Final measurement for ${measurable.layoutId} " +
1291-
"to confirm size ${child.width} ${child.height}"
1293+
"to confirm size ${child.width} ${child.height}"
12921294
)
12931295
}
12941296
measurable.measure(Constraints.fixed(child.width, child.height))
@@ -1566,11 +1568,13 @@ internal typealias SolverChain = androidx.constraintlayout.core.state.State.Chai
15661568
private val DEBUG = false
15671569
private fun ConstraintWidget.toDebugString() =
15681570
"$debugName " +
1569-
"width $width minWidth $minWidth maxWidth $maxWidth " +
1570-
"height $height minHeight $minHeight maxHeight $maxHeight " +
1571-
"HDB $horizontalDimensionBehaviour VDB $verticalDimensionBehaviour " +
1572-
"MCW $mMatchConstraintDefaultWidth MCH $mMatchConstraintDefaultHeight " +
1573-
"percentW $mMatchConstraintPercentWidth percentH $mMatchConstraintPercentHeight"
1574-
1575-
private fun BasicMeasure.Measure.toDebugString() =
1576-
"measure strategy is "
1571+
"width $width minWidth $minWidth maxWidth $maxWidth " +
1572+
"height $height minHeight $minHeight maxHeight $maxHeight " +
1573+
"HDB $horizontalDimensionBehaviour VDB $verticalDimensionBehaviour " +
1574+
"MCW $mMatchConstraintDefaultWidth MCH $mMatchConstraintDefaultHeight " +
1575+
"percentW $mMatchConstraintPercentWidth percentH $mMatchConstraintPercentHeight"
1576+
1577+
enum class LayoutInfoFlags {
1578+
NONE,
1579+
BOUNDS
1580+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal abstract class BaseHorizontalAnchorable(
121121

122122
internal object AnchorFunctions {
123123
val verticalAnchorFunctions:
124-
Array<Array<ConstraintReference.(Any, LayoutDirection) -> ConstraintReference>> =
124+
Array<Array<ConstraintReference.(Any, LayoutDirection) -> ConstraintReference>> =
125125
arrayOf(
126126
arrayOf(
127127
{ other, layoutDirection ->
@@ -180,7 +180,7 @@ internal object AnchorFunctions {
180180
}
181181

182182
val horizontalAnchorFunctions:
183-
Array<Array<ConstraintReference.(Any) -> ConstraintReference>> = arrayOf(
183+
Array<Array<ConstraintReference.(Any) -> ConstraintReference>> = arrayOf(
184184
arrayOf(
185185
{ other -> topToBottom(null); baselineToBaseline(null); topToTop(other) },
186186
{ other -> topToTop(null); baselineToBaseline(null); topToBottom(other) }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import androidx.constraintlayout.core.parser.CLParsingException
2323
import androidx.constraintlayout.core.state.ConstraintSetParser
2424
import androidx.constraintlayout.core.state.Transition
2525
import org.intellij.lang.annotations.Language
26-
import java.util.ArrayList
27-
import java.util.HashMap
2826

2927
internal class JSONConstraintSet(
3028
@Language("json5") content: String,
@@ -54,7 +52,7 @@ internal class JSONConstraintSet(
5452
override fun applyTo(transition: Transition, type: Int) {
5553
val layoutVariables = ConstraintSetParser.LayoutVariables()
5654
applyLayoutVariables(layoutVariables)
57-
ConstraintSetParser.parseJSON(getCurrentContent(), transition, type)
55+
ConstraintSetParser.parseJSON(getCurrentContent(), transition, type)
5856
}
5957

6058
fun emitDesignElements(designElements: ArrayList<ConstraintSetParser.DesignElement>) {

0 commit comments

Comments
 (0)