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

Commit 5a8ca65f authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Fix bug in AnimateToScene

This CL fixes a bug in AnimateToScene that would happen when triggering
a transition from A => B then directly back to B => A. When this
happened, we would snap directly to B instead of snapping to A.

Bug: 315921512
Test: SceneTransitionLayoutStateTest
Flag: N/A
Change-Id: Ia38a4d87bb288a9e25d123fc91076b7518e7f7ff
parent c1553651
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ internal fun CoroutineScope.animateToScene(
                    // The transition is already finished (progress ~= 1): no need to animate. We
                    // finish the current transition early to make sure that the current state
                    // change is committed.
                    layoutState.finishTransition(transitionState, transitionState.currentScene)
                    layoutState.finishTransition(transitionState, target)
                    null
                } else {
                    // The transition is in progress: start the canned animation at the same
@@ -78,7 +78,7 @@ internal fun CoroutineScope.animateToScene(
                if (progress.absoluteValue < ProgressVisibilityThreshold) {
                    // The transition is at progress ~= 0: no need to animate.We finish the current
                    // transition early to make sure that the current state change is committed.
                    layoutState.finishTransition(transitionState, transitionState.currentScene)
                    layoutState.finishTransition(transitionState, target)
                    null
                } else {
                    // TODO(b/290184746): Also take the current velocity into account.
+10 −0
Original line number Diff line number Diff line
@@ -90,6 +90,16 @@ class SceneTransitionLayoutStateTest {
        assertThat(state.transitionState).isEqualTo(TransitionState.Idle(TestScenes.SceneC))
    }

    @Test
    fun setTargetScene_transitionToOriginalScene() = runMonotonicClockTest {
        val state = MutableSceneTransitionLayoutState(TestScenes.SceneA)
        assertThat(state.setTargetScene(TestScenes.SceneB, coroutineScope = this)).isNotNull()

        // Progress is 0f, so we don't animate at all and directly snap back to A.
        assertThat(state.setTargetScene(TestScenes.SceneA, coroutineScope = this)).isNull()
        assertThat(state.transitionState).isEqualTo(TransitionState.Idle(TestScenes.SceneA))
    }

    @Test
    fun setTargetScene_coroutineScopeCancelled() = runMonotonicClockTest {
        val state = MutableSceneTransitionLayoutState(TestScenes.SceneA)