Loading packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt +3 −9 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ class SceneTransitionLayoutDataSource( } override fun snapToScene(toScene: SceneKey) { state.snapToScene(scene = toScene) state.snapTo(scene = toScene) } override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) { Loading Loading @@ -97,16 +97,10 @@ class SceneTransitionLayoutDataSource( } override fun instantlyShowOverlay(overlay: OverlayKey) { state.snapToScene( scene = state.transitionState.currentScene, currentOverlays = state.currentOverlays + overlay, ) state.snapTo(overlays = state.currentOverlays + overlay) } override fun instantlyHideOverlay(overlay: OverlayKey) { state.snapToScene( scene = state.transitionState.currentScene, currentOverlays = state.currentOverlays - overlay, ) state.snapTo(overlays = state.currentOverlays - overlay) } } packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutState.kt +9 −6 Original line number Diff line number Diff line Loading @@ -138,10 +138,13 @@ sealed interface MutableSceneTransitionLayoutState : SceneTransitionLayoutState transitionKey: TransitionKey? = null, ): Pair<TransitionState.Transition, Job>? /** Immediately snap to the given [scene]. */ fun snapToScene( scene: SceneKey, currentOverlays: Set<OverlayKey> = transitionState.currentOverlays, /** * Immediately snap to the given [scene] and/or [overlays], instantly interrupting all ongoing * transitions and settling to a [TransitionState.Idle] state. */ fun snapTo( scene: SceneKey = transitionState.currentScene, overlays: Set<OverlayKey> = transitionState.currentOverlays, ) /** Loading Loading @@ -554,7 +557,7 @@ internal class MutableSceneTransitionLayoutStateImpl( this.transitionStates = listOf(idle) } override fun snapToScene(scene: SceneKey, currentOverlays: Set<OverlayKey>) { override fun snapTo(scene: SceneKey, overlays: Set<OverlayKey>) { checkThread() // Force finish all transitions. Loading @@ -562,7 +565,7 @@ internal class MutableSceneTransitionLayoutStateImpl( check(transitionStates.size == 1) check(currentTransitions.isEmpty()) transitionStates = listOf(TransitionState.Idle(scene, currentOverlays)) transitionStates = listOf(TransitionState.Idle(scene, overlays)) } override fun showOverlay( Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ class ElementTest { rule.runOnUiThread { // We snap to scene B so that the transition A => B is removed from the list of // transitions. state.snapToScene(SceneB) state.snapTo(SceneB) state.setTargetScene(SceneC, coroutineScope) } } Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutStateTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -255,7 +255,7 @@ class SceneTransitionLayoutStateTest { assertThat(transition).hasCurrentScene(SceneB) // Snap to C. state.snapToScene(SceneC) state.snapTo(SceneC) assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) } Loading @@ -272,7 +272,7 @@ class SceneTransitionLayoutStateTest { assertThat(transition).hasToScene(SceneB) // Snap to C. state.snapToScene(SceneC) state.snapTo(SceneC) assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) } Loading Loading @@ -375,7 +375,7 @@ class SceneTransitionLayoutStateTest { val job = transition.coroutineScope.launch { awaitCancellation() } // Force snap state to SceneB to force finish all current transitions. state.snapToScene(SceneB) state.snapTo(SceneB) assertThat(state.transitionState).isIdle() assertThat(job.isCancelled).isTrue() } Loading Loading @@ -411,7 +411,7 @@ class SceneTransitionLayoutStateTest { val state = MutableSceneTransitionLayoutStateForTests(SceneA) state.startTransitionImmediately(this, transition(SceneA, SceneB)) state.startTransitionImmediately(this, transition(SceneB, SceneC)) state.snapToScene(SceneC) state.snapTo(SceneC) assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -457,9 +457,9 @@ class SceneTransitionLayoutTest { } // Snap to B then C to compose these scenes at least once. rule.runOnUiThread { state.snapToScene(SceneB) } rule.runOnUiThread { state.snapTo(SceneB) } rule.waitForIdle() rule.runOnUiThread { state.snapToScene(SceneC) } rule.runOnUiThread { state.snapTo(SceneC) } rule.waitForIdle() assertThat(keyInA).isEqualTo(SceneA) Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneTransitionLayoutDataSource.kt +3 −9 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ class SceneTransitionLayoutDataSource( } override fun snapToScene(toScene: SceneKey) { state.snapToScene(scene = toScene) state.snapTo(scene = toScene) } override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) { Loading Loading @@ -97,16 +97,10 @@ class SceneTransitionLayoutDataSource( } override fun instantlyShowOverlay(overlay: OverlayKey) { state.snapToScene( scene = state.transitionState.currentScene, currentOverlays = state.currentOverlays + overlay, ) state.snapTo(overlays = state.currentOverlays + overlay) } override fun instantlyHideOverlay(overlay: OverlayKey) { state.snapToScene( scene = state.transitionState.currentScene, currentOverlays = state.currentOverlays - overlay, ) state.snapTo(overlays = state.currentOverlays - overlay) } }
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutState.kt +9 −6 Original line number Diff line number Diff line Loading @@ -138,10 +138,13 @@ sealed interface MutableSceneTransitionLayoutState : SceneTransitionLayoutState transitionKey: TransitionKey? = null, ): Pair<TransitionState.Transition, Job>? /** Immediately snap to the given [scene]. */ fun snapToScene( scene: SceneKey, currentOverlays: Set<OverlayKey> = transitionState.currentOverlays, /** * Immediately snap to the given [scene] and/or [overlays], instantly interrupting all ongoing * transitions and settling to a [TransitionState.Idle] state. */ fun snapTo( scene: SceneKey = transitionState.currentScene, overlays: Set<OverlayKey> = transitionState.currentOverlays, ) /** Loading Loading @@ -554,7 +557,7 @@ internal class MutableSceneTransitionLayoutStateImpl( this.transitionStates = listOf(idle) } override fun snapToScene(scene: SceneKey, currentOverlays: Set<OverlayKey>) { override fun snapTo(scene: SceneKey, overlays: Set<OverlayKey>) { checkThread() // Force finish all transitions. Loading @@ -562,7 +565,7 @@ internal class MutableSceneTransitionLayoutStateImpl( check(transitionStates.size == 1) check(currentTransitions.isEmpty()) transitionStates = listOf(TransitionState.Idle(scene, currentOverlays)) transitionStates = listOf(TransitionState.Idle(scene, overlays)) } override fun showOverlay( Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -247,7 +247,7 @@ class ElementTest { rule.runOnUiThread { // We snap to scene B so that the transition A => B is removed from the list of // transitions. state.snapToScene(SceneB) state.snapTo(SceneB) state.setTargetScene(SceneC, coroutineScope) } } Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutStateTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -255,7 +255,7 @@ class SceneTransitionLayoutStateTest { assertThat(transition).hasCurrentScene(SceneB) // Snap to C. state.snapToScene(SceneC) state.snapTo(SceneC) assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) } Loading @@ -272,7 +272,7 @@ class SceneTransitionLayoutStateTest { assertThat(transition).hasToScene(SceneB) // Snap to C. state.snapToScene(SceneC) state.snapTo(SceneC) assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) } Loading Loading @@ -375,7 +375,7 @@ class SceneTransitionLayoutStateTest { val job = transition.coroutineScope.launch { awaitCancellation() } // Force snap state to SceneB to force finish all current transitions. state.snapToScene(SceneB) state.snapTo(SceneB) assertThat(state.transitionState).isIdle() assertThat(job.isCancelled).isTrue() } Loading Loading @@ -411,7 +411,7 @@ class SceneTransitionLayoutStateTest { val state = MutableSceneTransitionLayoutStateForTests(SceneA) state.startTransitionImmediately(this, transition(SceneA, SceneB)) state.startTransitionImmediately(this, transition(SceneB, SceneC)) state.snapToScene(SceneC) state.snapTo(SceneC) assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -457,9 +457,9 @@ class SceneTransitionLayoutTest { } // Snap to B then C to compose these scenes at least once. rule.runOnUiThread { state.snapToScene(SceneB) } rule.runOnUiThread { state.snapTo(SceneB) } rule.waitForIdle() rule.runOnUiThread { state.snapToScene(SceneC) } rule.runOnUiThread { state.snapTo(SceneC) } rule.waitForIdle() assertThat(keyInA).isEqualTo(SceneA) Loading