Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compose] Refactor out MotionLayout.kt classes #616

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ private class ConstraintLayoutParentData(
override val layoutId: Any = ref.id

override fun equals(other: Any?) = other is ConstraintLayoutParentData &&
ref.id == other.ref.id && constrain == other.constrain
ref.id == other.ref.id && constrain == other.constrain

override fun hashCode() = ref.id.hashCode() * 31 + constrain.hashCode()
}
Expand Down Expand Up @@ -722,7 +722,7 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
private var forcedWidth: Int = Int.MIN_VALUE
private var forcedHeight: Int = Int.MIN_VALUE
private var forcedDrawDebug: MotionLayoutDebugFlags =
MotionLayoutDebugFlags.UNKNOWN
MotionLayoutDebugFlags.UNKNOWN
private var updateFlag: MutableState<Long>? = null
private var layoutInformationMode: LayoutInfoFlags = LayoutInfoFlags.NONE
private var layoutInformation = ""
Expand Down Expand Up @@ -774,7 +774,8 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
val registry = Registry.getInstance()
registry.register(debugName, callback)
}
} catch (_: CLParsingException) {}
} catch (_: CLParsingException) {
}
}

// region Accessors
Expand Down Expand Up @@ -931,6 +932,7 @@ fun ConstraintSet(
class State(val density: Density) : SolverState() {
var rootIncomingConstraints: Constraints = Constraints()
lateinit var layoutDirection: LayoutDirection

init {
setDpToPixel { dp -> density.density * dp }
}
Expand Down Expand Up @@ -996,7 +998,7 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
Log.d(
"CCL",
"Measuring ${measurable.layoutId} with: " +
constraintWidget.toDebugString() + "\n" + measure.toDebugString()
constraintWidget.toDebugString() + "\n"
)
}

Expand Down Expand Up @@ -1033,11 +1035,11 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
}

if ((measure.measureStrategy == TRY_GIVEN_DIMENSIONS ||
measure.measureStrategy == USE_GIVEN_DIMENSIONS) ||
measure.measureStrategy == USE_GIVEN_DIMENSIONS) ||
!(measure.horizontalBehavior == MATCH_CONSTRAINT &&
constraintWidget.mMatchConstraintDefaultWidth == MATCH_CONSTRAINT_SPREAD &&
measure.verticalBehavior == MATCH_CONSTRAINT &&
constraintWidget.mMatchConstraintDefaultHeight == MATCH_CONSTRAINT_SPREAD)
constraintWidget.mMatchConstraintDefaultWidth == MATCH_CONSTRAINT_SPREAD &&
measure.verticalBehavior == MATCH_CONSTRAINT &&
constraintWidget.mMatchConstraintDefaultHeight == MATCH_CONSTRAINT_SPREAD)
) {
if (DEBUG) {
Log.d("CCL", "Measuring ${measurable.layoutId} with $constraints")
Expand Down Expand Up @@ -1103,7 +1105,7 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
.copyFrom(measure)

measure.measuredNeedsSolverPass = measure.measuredWidth != measure.horizontalDimension ||
measure.measuredHeight != measure.verticalDimension
measure.measuredHeight != measure.verticalDimension
}

fun addLayoutInformationReceiver(layoutReceiver: LayoutInformationReceiver?) {
Expand Down Expand Up @@ -1134,8 +1136,8 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
json.append(" interpolated: ")
json.append(
" { left: ${child.x}, top: ${child.y}, " +
"right: ${child.x + child.width}, " +
"bottom: ${child.y + child.height} }"
"right: ${child.x + child.width}, " +
"bottom: ${child.y + child.height} }"
)
json.append("}, ")
}
Expand Down Expand Up @@ -1192,11 +1194,11 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
Log.d("CCL", "IRH $currentDimensionResolved")
}
val useDimension = currentDimensionResolved ||
(measureStrategy == TRY_GIVEN_DIMENSIONS ||
measureStrategy == USE_GIVEN_DIMENSIONS) &&
(measureStrategy == USE_GIVEN_DIMENSIONS ||
matchConstraintDefaultDimension != MATCH_CONSTRAINT_WRAP ||
otherDimensionResolved)
(measureStrategy == TRY_GIVEN_DIMENSIONS ||
measureStrategy == USE_GIVEN_DIMENSIONS) &&
(measureStrategy == USE_GIVEN_DIMENSIONS ||
matchConstraintDefaultDimension != MATCH_CONSTRAINT_WRAP ||
otherDimensionResolved)
if (DEBUG) {
Log.d("CCL", "UD $useDimension")
}
Expand Down Expand Up @@ -1288,7 +1290,7 @@ internal open class Measurer : BasicMeasure.Measurer, DesignInfoProvider {
Log.d(
"CCL",
"Final measurement for ${measurable.layoutId} " +
"to confirm size ${child.width} ${child.height}"
"to confirm size ${child.width} ${child.height}"
)
}
measurable.measure(Constraints.fixed(child.width, child.height))
Expand Down Expand Up @@ -1566,11 +1568,13 @@ internal typealias SolverChain = androidx.constraintlayout.core.state.State.Chai
private val DEBUG = false
private fun ConstraintWidget.toDebugString() =
"$debugName " +
"width $width minWidth $minWidth maxWidth $maxWidth " +
"height $height minHeight $minHeight maxHeight $maxHeight " +
"HDB $horizontalDimensionBehaviour VDB $verticalDimensionBehaviour " +
"MCW $mMatchConstraintDefaultWidth MCH $mMatchConstraintDefaultHeight " +
"percentW $mMatchConstraintPercentWidth percentH $mMatchConstraintPercentHeight"

private fun BasicMeasure.Measure.toDebugString() =
"measure strategy is "
"width $width minWidth $minWidth maxWidth $maxWidth " +
"height $height minHeight $minHeight maxHeight $maxHeight " +
"HDB $horizontalDimensionBehaviour VDB $verticalDimensionBehaviour " +
"MCW $mMatchConstraintDefaultWidth MCH $mMatchConstraintDefaultHeight " +
"percentW $mMatchConstraintPercentWidth percentH $mMatchConstraintPercentHeight"

enum class LayoutInfoFlags {
NONE,
BOUNDS
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal abstract class BaseHorizontalAnchorable(

internal object AnchorFunctions {
val verticalAnchorFunctions:
Array<Array<ConstraintReference.(Any, LayoutDirection) -> ConstraintReference>> =
Array<Array<ConstraintReference.(Any, LayoutDirection) -> ConstraintReference>> =
arrayOf(
arrayOf(
{ other, layoutDirection ->
Expand Down Expand Up @@ -180,7 +180,7 @@ internal object AnchorFunctions {
}

val horizontalAnchorFunctions:
Array<Array<ConstraintReference.(Any) -> ConstraintReference>> = arrayOf(
Array<Array<ConstraintReference.(Any) -> ConstraintReference>> = arrayOf(
arrayOf(
{ other -> topToBottom(null); baselineToBaseline(null); topToTop(other) },
{ other -> topToTop(null); baselineToBaseline(null); topToBottom(other) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import androidx.constraintlayout.core.parser.CLParsingException
import androidx.constraintlayout.core.state.ConstraintSetParser
import androidx.constraintlayout.core.state.Transition
import org.intellij.lang.annotations.Language
import java.util.ArrayList
import java.util.HashMap

internal class JSONConstraintSet(
@Language("json5") content: String,
Expand Down Expand Up @@ -54,7 +52,7 @@ internal class JSONConstraintSet(
override fun applyTo(transition: Transition, type: Int) {
val layoutVariables = ConstraintSetParser.LayoutVariables()
applyLayoutVariables(layoutVariables)
ConstraintSetParser.parseJSON(getCurrentContent(), transition, type)
ConstraintSetParser.parseJSON(getCurrentContent(), transition, type)
}

fun emitDesignElements(designElements: ArrayList<ConstraintSetParser.DesignElement>) {
Expand Down
Loading