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

Commit 183ee498 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Expose the current scene key in SceneScope

Bug: 290930950
Test: atest SceneTransitionLayoutTest
Flag: com.android.systemui.scene_container
Change-Id: Iad082ca5d635099fbbf3c30201f1c1674d0f1a55
parent 14cf65b2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ internal class SceneScopeImpl(
    private val layoutImpl: SceneTransitionLayoutImpl,
    private val scene: Scene,
) : SceneScope, ElementStateScope by layoutImpl.elementStateScope {
    override val sceneKey: SceneKey = scene.key
    override val layoutState: SceneTransitionLayoutState = layoutImpl.state

    override fun Modifier.element(key: ElementKey): Modifier {
+3 −0
Original line number Diff line number Diff line
@@ -163,6 +163,9 @@ interface ElementStateScope {
@Stable
@ElementDsl
interface BaseSceneScope : ElementStateScope {
    /** The key of this scene. */
    val sceneKey: SceneKey

    /** The state of the [SceneTransitionLayout] in which this scene is contained. */
    val layoutState: SceneTransitionLayoutState

+26 −0
Original line number Diff line number Diff line
@@ -461,4 +461,30 @@ class SceneTransitionLayoutTest {
        assertThat(exception).hasMessageThat().contains(Back.toString())
        assertThat(exception).hasMessageThat().contains(SceneA.debugName)
    }

    @Test
    fun sceneKeyInScope() {
        val state = rule.runOnUiThread { MutableSceneTransitionLayoutState(SceneA) }

        var keyInA: SceneKey? = null
        var keyInB: SceneKey? = null
        var keyInC: SceneKey? = null
        rule.setContent {
            SceneTransitionLayout(state) {
                scene(SceneA) { keyInA = sceneKey }
                scene(SceneB) { keyInB = sceneKey }
                scene(SceneC) { keyInC = sceneKey }
            }
        }

        // Snap to B then C to compose these scenes at least once.
        rule.runOnUiThread { state.snapToScene(SceneB) }
        rule.waitForIdle()
        rule.runOnUiThread { state.snapToScene(SceneC) }
        rule.waitForIdle()

        assertThat(keyInA).isEqualTo(SceneA)
        assertThat(keyInB).isEqualTo(SceneB)
        assertThat(keyInC).isEqualTo(SceneC)
    }
}