Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a89da41a authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Introduce PropertyTransformation.Property

This CL introduces the notion of Property, which is used to understand
to which property a transformation is applied (instead of relying on
class hierarchy).

Bug: 376438969
Test: atest PlatformComposeSceneTransitionLayoutTests
Flag: com.android.systemui.scene_container
Change-Id: I9632d8892435eb9da1aba69315b67779279a3926
parent 93747b75
Loading
Loading
Loading
Loading
+16 −20
Original line number Diff line number Diff line
@@ -26,14 +26,6 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.util.fastForEach
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.animation.scene.transformation.CustomAlphaTransformation
import com.android.compose.animation.scene.transformation.CustomOffsetTransformation
import com.android.compose.animation.scene.transformation.CustomScaleTransformation
import com.android.compose.animation.scene.transformation.CustomSizeTransformation
import com.android.compose.animation.scene.transformation.InterpolatedAlphaTransformation
import com.android.compose.animation.scene.transformation.InterpolatedOffsetTransformation
import com.android.compose.animation.scene.transformation.InterpolatedScaleTransformation
import com.android.compose.animation.scene.transformation.InterpolatedSizeTransformation
import com.android.compose.animation.scene.transformation.PropertyTransformation
import com.android.compose.animation.scene.transformation.SharedElementTransformation
import com.android.compose.animation.scene.transformation.TransformationMatcher
@@ -358,13 +350,20 @@ internal class TransformationSpecImpl(
                return@fastForEach
            }

            when (val transformation = transformationMatcher.factory.create()) {
            val transformation = transformationMatcher.factory.create()
            val property =
                when (transformation) {
                    is SharedElementTransformation -> {
                        throwIfNotNull(shared, element, name = "shared")
                    shared = TransformationWithRange(transformation, transformationMatcher.range)
                        shared =
                            TransformationWithRange(transformation, transformationMatcher.range)
                        return@fastForEach
                    }
                    is PropertyTransformation<*> -> transformation.property
                }
                is InterpolatedOffsetTransformation,
                is CustomOffsetTransformation -> {

            when (property) {
                is PropertyTransformation.Property.Offset -> {
                    throwIfNotNull(offset, element, name = "offset")
                    offset =
                        TransformationWithRange(
@@ -372,8 +371,7 @@ internal class TransformationSpecImpl(
                            transformationMatcher.range,
                        )
                }
                is InterpolatedSizeTransformation,
                is CustomSizeTransformation -> {
                is PropertyTransformation.Property.Size -> {
                    throwIfNotNull(size, element, name = "size")
                    size =
                        TransformationWithRange(
@@ -381,8 +379,7 @@ internal class TransformationSpecImpl(
                            transformationMatcher.range,
                        )
                }
                is InterpolatedScaleTransformation,
                is CustomScaleTransformation -> {
                is PropertyTransformation.Property.Scale -> {
                    throwIfNotNull(drawScale, element, name = "drawScale")
                    drawScale =
                        TransformationWithRange(
@@ -390,8 +387,7 @@ internal class TransformationSpecImpl(
                            transformationMatcher.range,
                        )
                }
                is InterpolatedAlphaTransformation,
                is CustomAlphaTransformation -> {
                is PropertyTransformation.Property.Alpha -> {
                    throwIfNotNull(alpha, element, name = "alpha")
                    alpha =
                        TransformationWithRange(
+3 −1
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ private constructor(
    private val anchor: ElementKey,
    private val anchorWidth: Boolean,
    private val anchorHeight: Boolean,
) : InterpolatedSizeTransformation {
) : InterpolatedPropertyTransformation<IntSize> {
    override val property = PropertyTransformation.Property.Size

    override fun PropertyTransformationScope.transform(
        content: ContentKey,
        element: ElementKey,
+3 −1
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ import com.android.compose.animation.scene.content.state.TransitionState

/** Anchor the translation of an element to another element. */
internal class AnchoredTranslate private constructor(private val anchor: ElementKey) :
    InterpolatedOffsetTransformation {
    InterpolatedPropertyTransformation<Offset> {
    override val property = PropertyTransformation.Property.Offset

    override fun PropertyTransformationScope.transform(
        content: ContentKey,
        element: ElementKey,
+3 −1
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@ private constructor(
    private val scaleX: Float,
    private val scaleY: Float,
    private val pivot: Offset,
) : InterpolatedScaleTransformation {
) : InterpolatedPropertyTransformation<Scale> {
    override val property = PropertyTransformation.Property.Scale

    override fun PropertyTransformationScope.transform(
        content: ContentKey,
        element: ElementKey,
+3 −1
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ import com.android.compose.animation.scene.content.state.TransitionState
/** Translate an element from an edge of the layout. */
internal class EdgeTranslate
private constructor(private val edge: Edge, private val startsOutsideLayoutBounds: Boolean) :
    InterpolatedOffsetTransformation {
    InterpolatedPropertyTransformation<Offset> {
    override val property = PropertyTransformation.Property.Offset

    override fun PropertyTransformationScope.transform(
        content: ContentKey,
        element: ElementKey,
Loading