summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Johannes Gallmann <gallmann@google.com> 2024-10-31 14:14:50 +0100
committer Johannes Gallmann <gallmann@google.com> 2024-10-31 14:15:23 +0100
commit6ee02ccad60bacdb48e5f86359d1981feccfc7a1 (patch)
tree7d37425b2397ed8d6a23aaf99446f5f53767697d
parent5118004774dbcb5df0376a2b82e0270b67ab769b (diff)
[STL] Fix predictive back with activity-compose:1.10.0-alpha03
activity-compose:1.10.0-alpha03 introduced a stricter coroutine cancellation policy. The coroutine is now cancelled immediately when the PredictiveBackHandler is disabled. Therefore we have to run the transition on the animation scope instead. Bug: 376154092 Flag: EXEMPT bugfix Test: PredictiveBackHandlerTest Change-Id: I2c9eda8c6c51335c547b10430ecfb34db02752f0
-rw-r--r--packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/PredictiveBackHandler.kt1
-rw-r--r--packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transition/Seek.kt23
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()
}
}