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

Commit 906dad1c authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Move TransitionKey to Transition

This CL simply moves the TransitionKey associated to a transition inside
Transition itself, rather than binding it in STLState.startTransition.

Bug: 290930950
Test: atest PlatformComposeSceneTransitionLayoutTests
Flag: com.android.systemui.scene_container
Change-Id: I371c8b93ab6c216e7f89b9c06e41361287cf2094
parent 4b375c3e
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -109,8 +109,7 @@ internal fun CoroutineScope.animateToScene(
                    layoutState.transitions.interruptionHandler.onInterruption(
                        transitionState,
                        target,
                    )
                        ?: DefaultInterruptionHandler.onInterruption(transitionState, target)
                    ) ?: DefaultInterruptionHandler.onInterruption(transitionState, target)

                val animateFrom = interruptionResult.animateFrom
                if (
@@ -159,6 +158,7 @@ private fun CoroutineScope.animate(
    val transition =
        if (reversed) {
            OneOffTransition(
                key = transitionKey,
                fromScene = targetScene,
                toScene = fromScene,
                currentScene = targetScene,
@@ -167,6 +167,7 @@ private fun CoroutineScope.animate(
            )
        } else {
            OneOffTransition(
                key = transitionKey,
                fromScene = fromScene,
                toScene = targetScene,
                currentScene = targetScene,
@@ -178,7 +179,7 @@ private fun CoroutineScope.animate(
    // Change the current layout state to start this new transition. This will compute the
    // TransformationSpec associated to this transition, which we need to initialize the Animatable
    // that will actually animate it.
    layoutState.startTransition(transition, transitionKey, chain)
    layoutState.startTransition(transition, chain)

    // The transition now contains the transformation spec that we should use to instantiate the
    // Animatable.
@@ -207,6 +208,7 @@ private fun CoroutineScope.animate(
}

private class OneOffTransition(
    override val key: TransitionKey?,
    fromScene: SceneKey,
    toScene: SceneKey,
    override val currentScene: SceneKey,
+2 −2
Original line number Diff line number Diff line
@@ -257,7 +257,7 @@ private class DragControllerImpl(

    fun updateTransition(newTransition: SwipeTransition, force: Boolean = false) {
        if (isDrivingTransition || force) {
            layoutState.startTransition(newTransition, newTransition.key)
            layoutState.startTransition(newTransition)
        }

        swipeTransition = newTransition
@@ -555,7 +555,7 @@ private class SwipeTransition(
    val layoutImpl: SceneTransitionLayoutImpl,
    val layoutState: BaseSceneTransitionLayoutState,
    val coroutineScope: CoroutineScope,
    val key: TransitionKey?,
    override val key: TransitionKey?,
    val _fromScene: Scene,
    val _toScene: Scene,
    val userActionDistanceScope: UserActionDistanceScope,
+12 −7
Original line number Diff line number Diff line
@@ -225,6 +225,12 @@ sealed interface TransitionState {
        /** The scene this transition is going to. Can't be the same as fromScene */
        val toScene: SceneKey,
    ) : TransitionState {
        /**
         * The key of this transition. This should usually be null, but it can be specified to use a
         * specific set of transformations associated to this transition.
         */
        open val key: TransitionKey? = null

        /**
         * The progress of the transition. This is usually in the `[0; 1]` range, but it can also be
         * less than `0` or greater than `1` when using transitions with a spring AnimationSpec or
@@ -455,11 +461,7 @@ internal abstract class BaseSceneTransitionLayoutState(
     *
     * Important: you *must* call [finishTransition] once the transition is finished.
     */
    internal fun startTransition(
        transition: TransitionState.Transition,
        transitionKey: TransitionKey? = null,
        chain: Boolean = true,
    ) {
    internal fun startTransition(transition: TransitionState.Transition, chain: Boolean = true) {
        checkThread()

        // Compute the [TransformationSpec] when the transition starts.
@@ -469,7 +471,9 @@ internal abstract class BaseSceneTransitionLayoutState(

        // Update the transition specs.
        transition.transformationSpec =
            transitions.transitionSpec(fromScene, toScene, key = transitionKey).transformationSpec()
            transitions
                .transitionSpec(fromScene, toScene, key = transition.key)
                .transformationSpec()
        if (orientation != null) {
            transition.updateOverscrollSpecs(
                fromSpec = transitions.overscrollSpec(fromScene, orientation),
@@ -568,9 +572,10 @@ internal abstract class BaseSceneTransitionLayoutState(
                    originalTransition = transitionState,
                    fromScene = targetCurrentScene,
                    toScene = matchingLink.targetTo,
                    key = matchingLink.targetTransitionKey,
                )

            stateLink.target.startTransition(linkedTransition, matchingLink.targetTransitionKey)
            stateLink.target.startTransition(linkedTransition)
            activeTransitionLinks[stateLink] = linkedTransition
        }
    }
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.compose.animation.scene.transition.link

import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.TransitionKey
import com.android.compose.animation.scene.TransitionState
import kotlinx.coroutines.Job

@@ -25,6 +26,7 @@ internal class LinkedTransition(
    private val originalTransition: TransitionState.Transition,
    fromScene: SceneKey,
    toScene: SceneKey,
    override val key: TransitionKey? = null,
) : TransitionState.Transition(fromScene, toScene) {

    override val currentScene: SceneKey
+8 −13
Original line number Diff line number Diff line
@@ -638,10 +638,7 @@ class ElementTest {

        // Change the current transition.
        rule.runOnUiThread {
            state.startTransition(
                transition(from = SceneA, to = SceneB, progress = { 0.5f }),
                transitionKey = null,
            )
            state.startTransition(transition(from = SceneA, to = SceneB, progress = { 0.5f }))
        }

        // The size of Foo should still be 20dp given that the new state was not composed yet.
@@ -1170,7 +1167,7 @@ class ElementTest {
        val offsetInAToB = lerp(offsetInA, offsetInB, aToBProgress)
        val sizeInAToB = lerp(sizeInA, sizeInB, aToBProgress)
        val valueInAToB = lerp(valueInA, valueInB, aToBProgress)
        rule.runOnUiThread { state.startTransition(aToB, transitionKey = null) }
        rule.runOnUiThread { state.startTransition(aToB) }
        rule
            .onNode(isElement(TestElements.Foo, SceneB))
            .assertSizeIsEqualTo(sizeInAToB)
@@ -1190,7 +1187,7 @@ class ElementTest {
                progress = { bToCProgress },
                interruptionProgress = { interruptionProgress },
            )
        rule.runOnUiThread { state.startTransition(bToC, transitionKey = null) }
        rule.runOnUiThread { state.startTransition(bToC) }

        // The interruption deltas, which will be multiplied by the interruption progress then added
        // to the current transition offset and size.
@@ -1332,9 +1329,9 @@ class ElementTest {
                interruptionProgress = { bToCInterruptionProgress },
                onFinish = neverFinish(),
            )
        rule.runOnUiThread { state.startTransition(aToB, transitionKey = null) }
        rule.runOnUiThread { state.startTransition(aToB) }
        rule.waitForIdle()
        rule.runOnUiThread { state.startTransition(bToC, transitionKey = null) }
        rule.runOnUiThread { state.startTransition(bToC) }

        // Foo is placed in both B and C given that the shared transition is disabled. In B, its
        // offset is impacted by the interruption but in C it is not.
@@ -1370,7 +1367,7 @@ class ElementTest {
                progress = { 0.7f },
                interruptionProgress = { 1f },
            )
        rule.runOnUiThread { state.startTransition(bToA, transitionKey = null) }
        rule.runOnUiThread { state.startTransition(bToA) }

        // Foo should have the position it had in B right before the interruption.
        rule
@@ -1394,8 +1391,7 @@ class ElementTest {
                                to = SceneB,
                                progress = { -1f },
                                orientation = Orientation.Horizontal
                            ),
                            transitionKey = null,
                            )
                        )
                    }
            }
@@ -1512,8 +1508,7 @@ class ElementTest {
                    to = SceneB,
                    progress = { 0.6f },
                    interruptionProgress = { interruptionProgress },
                ),
                transitionKey = null
                )
            )
        }
        rule.waitForIdle()
Loading