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

Commit e4a75f90 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Alejandro Nijamkin
Browse files

Add MutableSTLState.snapToScene()

This CL adds a new snapToScene() function to MutableSTLState that can be
used to immediately snap to a scene. This can for instance be useful to
make sure that the Shade is immediately hidden after a launch
transition.

Bug: 330672236
Test: atest SceneTransitionLayoutStateTest
Flag: N/A
Change-Id: I37d59c20d8634bdb9d0486e8726006b6fe29b9cb
parent c66333f1
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -117,6 +117,9 @@ sealed interface MutableSceneTransitionLayoutState : SceneTransitionLayoutState
        coroutineScope: CoroutineScope,
        transitionKey: TransitionKey? = null,
    ): TransitionState.Transition?

    /** Immediately snap to the given [scene]. */
    fun snapToScene(scene: SceneKey)
}

/**
@@ -735,6 +738,17 @@ internal class MutableSceneTransitionLayoutStateImpl(
    override fun CoroutineScope.onChangeScene(scene: SceneKey) {
        setTargetScene(scene, coroutineScope = this)
    }

    override fun snapToScene(scene: SceneKey) {
        // Force finish all transitions.
        while (currentTransitions.isNotEmpty()) {
            val transition = transitionStates[0] as TransitionState.Transition
            finishTransition(transition, transition.currentScene)
        }

        check(transitionStates.size == 1)
        transitionStates[0] = TransitionState.Idle(scene)
    }
}

private const val TAG = "SceneTransitionLayoutState"
+15 −0
Original line number Diff line number Diff line
@@ -629,4 +629,19 @@ class SceneTransitionLayoutStateTest {
            Log.setWtfHandler(originalHandler)
        }
    }

    @Test
    fun snapToScene() = runMonotonicClockTest {
        val state = MutableSceneTransitionLayoutState(SceneA)

        // Transition to B.
        state.setTargetScene(SceneB, coroutineScope = this)
        val transition = assertThat(state.transitionState).isTransition()
        assertThat(transition).hasCurrentScene(SceneB)

        // Snap to C.
        state.snapToScene(SceneC)
        assertThat(state.transitionState).isIdle()
        assertThat(state.transitionState).hasCurrentScene(SceneC)
    }
}