diff options
2 files changed, 18 insertions, 6 deletions
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/PredictiveBackHandler.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/PredictiveBackHandler.kt index b00c8ade07eb..8a6a0d6dbb99 100644 --- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/PredictiveBackHandler.kt +++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/PredictiveBackHandler.kt @@ -70,6 +70,7 @@ internal fun PredictiveBackHandler( // The predictive back APIs will automatically animate the progress for us in this case // so there is no need to animate it. cancelSpec = snap(), + animationScope = layoutImpl.animationScope, ) } } diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transition/Seek.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transition/Seek.kt index 715d979e116e..2b33224022fc 100644 --- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transition/Seek.kt +++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transition/Seek.kt @@ -30,6 +30,8 @@ import com.android.compose.animation.scene.TransitionKey import com.android.compose.animation.scene.UserActionResult import com.android.compose.animation.scene.createSwipeAnimation import kotlin.coroutines.cancellation.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collectLatest @@ -141,6 +143,7 @@ internal suspend fun <T : ContentKey> animateProgress( progress: Flow<Float>, commitSpec: AnimationSpec<Float>?, cancelSpec: AnimationSpec<Float>?, + animationScope: CoroutineScope? = null, ) { fun animateOffset(targetContent: T, spec: AnimationSpec<Float>?) { if (state.transitionState != animation.contentTransition || animation.isAnimatingOffset()) { @@ -176,12 +179,20 @@ internal suspend fun <T : ContentKey> animateProgress( } // Start the transition. - state.startTransition(animation.contentTransition) + animationScope?.launch { startTransition(state, animation, collectionJob) } + ?: startTransition(state, animation, collectionJob) + } +} - // The transition is done. Cancel the collection in case the transition was finished because - // it was interrupted by another transition. - if (collectionJob.isActive) { - collectionJob.cancel() - } +private suspend fun <T : ContentKey> startTransition( + state: MutableSceneTransitionLayoutStateImpl, + animation: SwipeAnimation<T>, + progressCollectionJob: Job, +) { + state.startTransition(animation.contentTransition) + // The transition is done. Cancel the collection in case the transition was finished + // because it was interrupted by another transition. + if (progressCollectionJob.isActive) { + progressCollectionJob.cancel() } } |