@@ -63,6 +63,7 @@ import androidx.compose.ui.unit.sp
63
63
import androidx.compose.ui.util.fastAny
64
64
import androidx.compose.ui.util.fastForEach
65
65
import androidx.constraintlayout.core.motion.Motion
66
+ import androidx.constraintlayout.core.parser.CLObject
66
67
import androidx.constraintlayout.core.parser.CLParser
67
68
import androidx.constraintlayout.core.parser.CLParsingException
68
69
import androidx.constraintlayout.core.state.ConstraintSetParser.parseMotionSceneJSON
@@ -184,7 +185,7 @@ inline fun MotionLayout(
184
185
MotionLayoutCore (
185
186
start = start,
186
187
end = end,
187
- transition = transition,
188
+ transition = transition as ? TransitionImpl ,
188
189
progress = progress,
189
190
debug = debug,
190
191
informationReceiver = informationReceiver,
@@ -368,7 +369,7 @@ internal inline fun MotionLayoutCore(
368
369
MotionLayoutCore (
369
370
start = start,
370
371
end = end,
371
- transition = transition,
372
+ transition = transition as ? TransitionImpl ,
372
373
progress = usedProgress,
373
374
debug = usedDebugMode,
374
375
informationReceiver = motionScene as ? LayoutInformationReceiver ,
@@ -384,7 +385,7 @@ internal inline fun MotionLayoutCore(
384
385
internal inline fun MotionLayoutCore (
385
386
start : ConstraintSet ,
386
387
end : ConstraintSet ,
387
- transition : androidx.constraintlayout.compose. Transition ? = null,
388
+ transition : TransitionImpl ? = null,
388
389
progress : Float ,
389
390
debug : EnumSet <MotionLayoutDebugFlags > = EnumSet .of(MotionLayoutDebugFlags .NONE ),
390
391
informationReceiver : LayoutInformationReceiver ? = null,
@@ -506,7 +507,7 @@ internal inline fun MotionLayoutCore(
506
507
motionScene,
507
508
start,
508
509
end,
509
- transition,
510
+ transition as ? TransitionImpl ,
510
511
motionLayoutState.progressState,
511
512
measurer
512
513
)
@@ -722,12 +723,52 @@ class MotionLayoutScope @PublishedApi internal constructor(
722
723
*/
723
724
@Immutable
724
725
interface Transition {
725
- fun applyAllTo (transition : Transition , type : Int )
726
- fun applyKeyFramesTo (transition : Transition )
727
726
fun getStartConstraintSetId (): String
728
727
fun getEndConstraintSetId (): String
729
728
}
730
729
730
+ /* *
731
+ * Subclass of [Transition] for internal use.
732
+ *
733
+ * Used to reduced the exposed API from [Transition].
734
+ */
735
+ internal class TransitionImpl (
736
+ private val parsedTransition : CLObject ,
737
+ private val pixelDp : CorePixelDp
738
+ ) : androidx.constraintlayout.compose.Transition {
739
+
740
+ /* *
741
+ * Applies all Transition properties to [transition].
742
+ */
743
+ fun applyAllTo (transition : Transition , type : Int ) {
744
+ try {
745
+ TransitionParser .parse(parsedTransition, transition, pixelDp)
746
+ } catch (e: CLParsingException ) {
747
+ Log .e(" CML" , " Error parsing JSON $e " )
748
+ }
749
+ }
750
+
751
+ /* *
752
+ * Applies only the KeyFrame related properties (KeyCycles, KeyAttributes, KeyPositions) to
753
+ * [transition], which effectively sets the respective parameters for each WidgetState.
754
+ */
755
+ fun applyKeyFramesTo (transition : Transition ) {
756
+ try {
757
+ TransitionParser .parseKeyFrames(parsedTransition, transition)
758
+ } catch (e: CLParsingException ) {
759
+ Log .e(" CML" , " Error parsing JSON $e " )
760
+ }
761
+ }
762
+
763
+ override fun getStartConstraintSetId (): String {
764
+ return parsedTransition.getStringOrNull(" from" ) ? : " start"
765
+ }
766
+
767
+ override fun getEndConstraintSetId (): String {
768
+ return parsedTransition.getStringOrNull(" to" ) ? : " end"
769
+ }
770
+ }
771
+
731
772
/* *
732
773
* Parses the given JSON5 into a [Transition].
733
774
*
@@ -746,33 +787,8 @@ fun Transition(@Language("json5") content: String): androidx.constraintlayout.co
746
787
}
747
788
mutableStateOf(
748
789
if (parsed != null ) {
749
- object : androidx.constraintlayout.compose.Transition {
750
- val pixelDp = CorePixelDp { dpValue -> dpValue * dpToPixel }
751
-
752
- override fun applyAllTo (transition : Transition , type : Int ) {
753
- try {
754
- TransitionParser .parse(parsed, transition, pixelDp)
755
- } catch (e: CLParsingException ) {
756
- Log .e(" CML" , " Error parsing JSON $e " )
757
- }
758
- }
759
-
760
- override fun applyKeyFramesTo (transition : Transition ) {
761
- try {
762
- TransitionParser .parseKeyFrames(parsed, transition)
763
- } catch (e: CLParsingException ) {
764
- Log .e(" CML" , " Error parsing JSON $e " )
765
- }
766
- }
767
-
768
- override fun getStartConstraintSetId (): String {
769
- return parsed.getStringOrNull(" from" ) ? : " start"
770
- }
771
-
772
- override fun getEndConstraintSetId (): String {
773
- return parsed.getStringOrNull(" to" ) ? : " end"
774
- }
775
- }
790
+ val pixelDp = CorePixelDp { dpValue -> dpValue * dpToPixel }
791
+ TransitionImpl (parsed, pixelDp)
776
792
} else {
777
793
null
778
794
}
@@ -800,7 +816,7 @@ internal fun rememberMotionLayoutMeasurePolicy(
800
816
needsUpdate : Long ,
801
817
constraintSetStart : ConstraintSet ,
802
818
constraintSetEnd : ConstraintSet ,
803
- transition : androidx.constraintlayout.compose. Transition ? ,
819
+ transition : TransitionImpl ? ,
804
820
progress : MutableState <Float >,
805
821
measurer : MotionMeasurer
806
822
) = remember(
@@ -840,7 +856,7 @@ internal fun rememberMotionLayoutMeasurePolicy(
840
856
motionScene : MotionScene ,
841
857
constraintSetStart : ConstraintSet ,
842
858
constraintSetEnd : ConstraintSet ,
843
- transition : androidx.constraintlayout.compose. Transition ? ,
859
+ transition : TransitionImpl ? ,
844
860
progress : State <Float >,
845
861
measurer : MotionMeasurer
846
862
) = remember(
@@ -921,7 +937,7 @@ internal class MotionMeasurer : Measurer() {
921
937
layoutDirection : LayoutDirection ,
922
938
constraintSetStart : ConstraintSet ,
923
939
constraintSetEnd : ConstraintSet ,
924
- transition : androidx.constraintlayout.compose. Transition ? ,
940
+ transition : TransitionImpl ? ,
925
941
measurables : List <Measurable >,
926
942
optimizationLevel : Int ,
927
943
progress : Float ,
@@ -999,7 +1015,7 @@ internal class MotionMeasurer : Measurer() {
999
1015
layoutDirection : LayoutDirection ,
1000
1016
constraintSetStart : ConstraintSet ,
1001
1017
constraintSetEnd : ConstraintSet ,
1002
- transition : androidx.constraintlayout.compose. Transition ? ,
1018
+ transition : TransitionImpl ? ,
1003
1019
measurables : List <Measurable >,
1004
1020
optimizationLevel : Int ,
1005
1021
progress : Float ,
@@ -1335,7 +1351,7 @@ internal class MotionMeasurer : Measurer() {
1335
1351
fun initWith (
1336
1352
start : ConstraintSet ,
1337
1353
end : ConstraintSet ,
1338
- transition : androidx.constraintlayout.compose. Transition ? ,
1354
+ transition : TransitionImpl ? ,
1339
1355
progress : Float
1340
1356
) {
1341
1357
clearConstraintSets()
0 commit comments