Loading packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/state/TransitionState.kt +16 −0 Original line number Diff line number Diff line Loading @@ -311,6 +311,22 @@ sealed interface TransitionState { return fromContent == content || toContent == content } /** * Return [progress] if [content] is equal to [toContent], `1f - progress` if [content] is * equal to [fromContent], and throw otherwise. */ fun progressTo(content: ContentKey): Float { return when (content) { toContent -> progress fromContent -> 1f - progress else -> throw IllegalArgumentException( "content ($content) should be either toContent ($toContent) or " + "fromContent ($fromContent)" ) } } /** Run this transition and return once it is finished. */ abstract suspend fun run() Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutStateTest.kt +9 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Assert.assertThrows import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -768,4 +769,12 @@ class SceneTransitionLayoutStateTest { assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) } @Test fun transition_progressTo() { val transition = transition(from = SceneA, to = SceneB, progress = { 0.2f }) assertThat(transition.progressTo(SceneB)).isEqualTo(0.2f) assertThat(transition.progressTo(SceneA)).isEqualTo(1f - 0.2f) assertThrows(IllegalArgumentException::class.java) { transition.progressTo(SceneC) } } } Loading
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/state/TransitionState.kt +16 −0 Original line number Diff line number Diff line Loading @@ -311,6 +311,22 @@ sealed interface TransitionState { return fromContent == content || toContent == content } /** * Return [progress] if [content] is equal to [toContent], `1f - progress` if [content] is * equal to [fromContent], and throw otherwise. */ fun progressTo(content: ContentKey): Float { return when (content) { toContent -> progress fromContent -> 1f - progress else -> throw IllegalArgumentException( "content ($content) should be either toContent ($toContent) or " + "fromContent ($fromContent)" ) } } /** Run this transition and return once it is finished. */ abstract suspend fun run() Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneTransitionLayoutStateTest.kt +9 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Assert.assertThrows import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -768,4 +769,12 @@ class SceneTransitionLayoutStateTest { assertThat(state.transitionState).isIdle() assertThat(state.transitionState).hasCurrentScene(SceneC) } @Test fun transition_progressTo() { val transition = transition(from = SceneA, to = SceneB, progress = { 0.2f }) assertThat(transition.progressTo(SceneB)).isEqualTo(0.2f) assertThat(transition.progressTo(SceneA)).isEqualTo(1f - 0.2f) assertThrows(IllegalArgumentException::class.java) { transition.progressTo(SceneC) } } }