Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a98256ac authored by Johannes Gallmann's avatar Johannes Gallmann Committed by Android (Google) Code Review
Browse files

Merge "[STL] Fix predictive back with activity-compose:1.10.0-alpha03" into main

parents d2e98330 6ee02cca
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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,
        )
    }
}
+17 −6
Original line number Diff line number Diff line
@@ -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)

        // 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()
        animationScope?.launch { startTransition(state, animation, collectionJob) }
            ?: startTransition(state, animation, collectionJob)
    }
}

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()
    }
}