Loading packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutState.kt +9 −1 Original line number Diff line number Diff line Loading @@ -356,6 +356,12 @@ internal class MutableSceneTransitionLayoutStateImpl( override suspend fun startTransition(transition: TransitionState.Transition, chain: Boolean) { checkThread() // Prepare the transition before starting it. This is outside of the try/finally block on // purpose because preparing a transition might throw an exception (e.g. if we find multiple // specs matching this transition), in which case we want to throw that exception here // before even starting the transition. prepareTransitionBeforeStarting(transition) try { // Start the transition. startTransitionInternal(transition, chain) Loading @@ -367,7 +373,7 @@ internal class MutableSceneTransitionLayoutStateImpl( } } private fun startTransitionInternal(transition: TransitionState.Transition, chain: Boolean) { private fun prepareTransitionBeforeStarting(transition: TransitionState.Transition) { // Set the current scene and overlays on the transition. val currentState = transitionState transition.currentSceneWhenTransitionStarted = currentState.currentScene Loading Loading @@ -395,7 +401,9 @@ internal class MutableSceneTransitionLayoutStateImpl( } else { transition.updateOverscrollSpecs(fromSpec = null, toSpec = null) } } private fun startTransitionInternal(transition: TransitionState.Transition, chain: Boolean) { when (val currentState = transitionStates.last()) { is TransitionState.Idle -> { // Replace [Idle] by [transition]. Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutStateTest.kt +26 −0 Original line number Diff line number Diff line Loading @@ -686,4 +686,30 @@ class SceneTransitionLayoutStateTest { assertThat(state.transitionState).isIdle() assertThat(job.isCancelled).isTrue() } @Test fun badTransitionSpecThrowsMeaningfulMessageWhenStartingTransition() { val state = MutableSceneTransitionLayoutState( SceneA, transitions { // This transition definition is bad because they both match when transitioning // from A to B. from(SceneA) {} to(SceneB) {} }, ) val exception = assertThrows(IllegalStateException::class.java) { runBlocking { state.startTransition(transition(from = SceneA, to = SceneB)) } } assertThat(exception) .hasMessageThat() .isEqualTo( "Found multiple transition specs for transition SceneKey(debugName=SceneA) => " + "SceneKey(debugName=SceneB)" ) } } Loading
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutState.kt +9 −1 Original line number Diff line number Diff line Loading @@ -356,6 +356,12 @@ internal class MutableSceneTransitionLayoutStateImpl( override suspend fun startTransition(transition: TransitionState.Transition, chain: Boolean) { checkThread() // Prepare the transition before starting it. This is outside of the try/finally block on // purpose because preparing a transition might throw an exception (e.g. if we find multiple // specs matching this transition), in which case we want to throw that exception here // before even starting the transition. prepareTransitionBeforeStarting(transition) try { // Start the transition. startTransitionInternal(transition, chain) Loading @@ -367,7 +373,7 @@ internal class MutableSceneTransitionLayoutStateImpl( } } private fun startTransitionInternal(transition: TransitionState.Transition, chain: Boolean) { private fun prepareTransitionBeforeStarting(transition: TransitionState.Transition) { // Set the current scene and overlays on the transition. val currentState = transitionState transition.currentSceneWhenTransitionStarted = currentState.currentScene Loading Loading @@ -395,7 +401,9 @@ internal class MutableSceneTransitionLayoutStateImpl( } else { transition.updateOverscrollSpecs(fromSpec = null, toSpec = null) } } private fun startTransitionInternal(transition: TransitionState.Transition, chain: Boolean) { when (val currentState = transitionStates.last()) { is TransitionState.Idle -> { // Replace [Idle] by [transition]. Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutStateTest.kt +26 −0 Original line number Diff line number Diff line Loading @@ -686,4 +686,30 @@ class SceneTransitionLayoutStateTest { assertThat(state.transitionState).isIdle() assertThat(job.isCancelled).isTrue() } @Test fun badTransitionSpecThrowsMeaningfulMessageWhenStartingTransition() { val state = MutableSceneTransitionLayoutState( SceneA, transitions { // This transition definition is bad because they both match when transitioning // from A to B. from(SceneA) {} to(SceneB) {} }, ) val exception = assertThrows(IllegalStateException::class.java) { runBlocking { state.startTransition(transition(from = SceneA, to = SceneB)) } } assertThat(exception) .hasMessageThat() .isEqualTo( "Found multiple transition specs for transition SceneKey(debugName=SceneA) => " + "SceneKey(debugName=SceneB)" ) } }