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

Commit 3a2a318

Browse files
oscar-adjafu888
authored andcommitted
[Compose] Refactory internal MotionLayout API
Makes it so that all public MotionLayout calls converge to the same method. This way, manipulating the layout internally is more consistent and works over the same API (see MotionProgress). For consistency with Link functionality, LayoutInformationReceiver now has all Link related methods. Marked ConstraintSet classes as Immutable.
1 parent c328f1f commit 3a2a318

File tree

14 files changed

+214
-268
lines changed

14 files changed

+214
-268
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ fun Dimension.MaxCoercible.atMost(dp: Dp): Dimension =
658658
(this as DimensionDescription).also { it.max = dp }
659659

660660
/**
661-
* Sets the upper bound of the current [Dimension] to be the [Wrap] size of the child.
661+
* Sets the upper bound of the current [Dimension] to be the [WRAP_DIMENSION] size of the child.
662662
*/
663663
val Dimension.MaxCoercible.atMostWrapContent: Dimension
664664
get() = (this as DimensionDescription).also { it.maxSymbol = WRAP_DIMENSION }
@@ -779,7 +779,7 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
779779
}
780780

781781
// region Accessors
782-
fun setUpdateFlag(needsUpdate: MutableState<Long>) {
782+
override fun setUpdateFlag(needsUpdate: MutableState<Long>) {
783783
updateFlag = needsUpdate
784784
}
785785

@@ -805,7 +805,7 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
805805
return debugName
806806
}
807807

808-
fun getForcedDrawDebug(): MotionLayoutDebugFlags {
808+
override fun getForcedDrawDebug(): MotionLayoutDebugFlags {
809809
return forcedDrawDebug
810810
}
811811

@@ -856,10 +856,6 @@ internal abstract class EditableJSONLayout(@Language("json5") content: String) :
856856
}
857857
}
858858

859-
protected open fun onNewProgress(progress: Float) {
860-
// nothing for ConstraintSet
861-
}
862-
863859
fun onNewDimensions(width: Int, height: Int) {
864860
forcedWidth = width
865861
forcedHeight = height
@@ -959,6 +955,20 @@ interface LayoutInformationReceiver {
959955
fun getLayoutInformationMode(): LayoutInfoFlags
960956
fun getForcedWidth(): Int
961957
fun getForcedHeight(): Int
958+
fun setUpdateFlag(needsUpdate: MutableState<Long>)
959+
fun getForcedDrawDebug(): MotionLayoutDebugFlags
960+
961+
/**
962+
* reset the force progress flag
963+
*/
964+
fun resetForcedProgress()
965+
966+
/**
967+
* Get the progress of the force progress
968+
*/
969+
fun getForcedProgress(): Float
970+
971+
fun onNewProgress(progress: Float)
962972
}
963973

964974
@PublishedApi

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface ConstraintSet {
3838
fun isDirty(measurables: List<Measurable>): Boolean = true
3939
}
4040

41+
@Immutable
4142
internal interface DerivedConstraintSet : ConstraintSet {
4243
/**
4344
* [ConstraintSet] that this instance will derive its constraints from.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
package androidx.constraintlayout.compose
1818

19+
import androidx.compose.runtime.Immutable
20+
1921
/**
2022
* [ConstraintSet] implementation used in the kotlin DSL.
2123
*/
24+
@Immutable
2225
internal class DslConstraintSet constructor(
2326
val description: ConstraintSetScope.() -> Unit,
2427
override val extendFrom: ConstraintSet? = null

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package androidx.constraintlayout.compose
1818

19+
import androidx.compose.runtime.Immutable
1920
import androidx.compose.ui.layout.Measurable
2021
import androidx.constraintlayout.core.parser.CLKey
2122
import androidx.constraintlayout.core.parser.CLParser
@@ -24,6 +25,7 @@ import androidx.constraintlayout.core.state.ConstraintSetParser
2425
import androidx.constraintlayout.core.state.Transition
2526
import org.intellij.lang.annotations.Language
2627

28+
@Immutable
2729
internal class JSONConstraintSet(
2830
@Language("json5") content: String,
2931
@Language("json5") overrideVariables: String? = null,
@@ -71,7 +73,6 @@ internal class JSONConstraintSet(
7173
// TODO: Need to better handle half parsed JSON and/or incorrect states.
7274
try {
7375
ConstraintSetParser.parseJSON(getCurrentContent(), state, layoutVariables)
74-
7576
_isDirty = false
7677
} catch (e: Exception) {
7778
// nothing (content might be invalid, sent by live edit)
@@ -107,4 +108,17 @@ internal class JSONConstraintSet(
107108
layoutVariables.putOverride(name, overridedVariables[name]!!)
108109
}
109110
}
111+
112+
override fun resetForcedProgress() {
113+
// Nothing for ConstraintSet
114+
}
115+
116+
override fun getForcedProgress(): Float {
117+
// Nothing for ConstraintSet
118+
return 0f
119+
}
120+
121+
override fun onNewProgress(progress: Float) {
122+
// Nothing for ConstraintSet
123+
}
110124
}

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package androidx.constraintlayout.compose
1919
import android.annotation.SuppressLint
2020
import androidx.compose.foundation.gestures.detectDragGestures
2121
import androidx.compose.runtime.LaunchedEffect
22-
import androidx.compose.runtime.MutableState
2322
import androidx.compose.runtime.remember
2423
import androidx.compose.ui.Modifier
2524
import androidx.compose.ui.composed
@@ -32,32 +31,6 @@ import kotlinx.coroutines.channels.Channel
3231
import kotlinx.coroutines.ensureActive
3332
import kotlinx.coroutines.isActive
3433

35-
/**
36-
* Helper modifier for MotionLayout to support OnSwipe in Transitions.
37-
*
38-
* @see Modifier.pointerInput
39-
* @see TransitionHandler
40-
*/
41-
@SuppressLint("UnnecessaryComposedModifier")
42-
@Suppress("NOTHING_TO_INLINE")
43-
@PublishedApi
44-
internal inline fun Modifier.motionPointerInput(
45-
key: Any = Unit,
46-
progressState: MutableState<Float>,
47-
measurer: MotionMeasurer
48-
): Modifier {
49-
val motionProgress: MotionProgress =
50-
object : MotionProgress {
51-
override val progress: Float
52-
get() = progressState.value
53-
54-
override suspend fun updateProgress(newProgress: Float) {
55-
progressState.value = newProgress
56-
}
57-
}
58-
return this.motionPointerInput(key, motionProgress, measurer)
59-
}
60-
6134
/**
6235
* Helper modifier for MotionLayout to support OnSwipe in Transitions.
6336
*

0 commit comments

Comments
 (0)