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

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

Revert "Respect animationSpec for predictive back transition in STL"

This reverts commit fac45418.

Reason for revert: b/357726958

Change-Id: I225a7e48e6969468d8d8f614f418fef79945f616
parent fac45418
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -126,16 +126,7 @@ private class PredictiveBackTransition(
        return coroutineScope
            .launch(start = CoroutineStart.ATOMIC) {
                try {
                    if (currentScene == toScene) {
                        animatable.animateTo(targetProgress, transformationSpec.progressSpec)
                    } else {
                        // If the back gesture is cancelled, the progress is animated back to 0f by
                        // the system. But we need this animate call anyways because
                        // PredictiveBackHandler doesn't guarantee that it ends at 0f. Since the
                        // remaining change in progress is usually very small, the progressSpec is
                        // omitted and the default spring spec used instead.
                    animatable.animateTo(targetProgress)
                    }
                } finally {
                    state.finishTransition(this@PredictiveBackTransition, scene)
                }
+1 −34
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.compose.animation.scene

import androidx.activity.BackEventCompat
import androidx.activity.ComponentActivity
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.rememberCoroutineScope
@@ -61,23 +59,7 @@ class PredictiveBackHandlerTest {

    @Test
    fun testPredictiveBack() {
        val transitionFrames = 2
        val layoutState =
            rule.runOnUiThread {
                MutableSceneTransitionLayoutState(
                    SceneA,
                    transitions =
                        transitions {
                            from(SceneA, to = SceneB) {
                                spec =
                                    tween(
                                        durationMillis = transitionFrames * 16,
                                        easing = LinearEasing
                                    )
                            }
                        }
                )
            }
        val layoutState = rule.runOnUiThread { MutableSceneTransitionLayoutState(SceneA) }
        rule.setContent {
            SceneTransitionLayout(layoutState) {
                scene(SceneA, mapOf(Back to SceneB)) { Box(Modifier.fillMaxSize()) }
@@ -106,27 +88,12 @@ class PredictiveBackHandlerTest {
        assertThat(layoutState.transitionState).hasCurrentScene(SceneA)
        assertThat(layoutState.transitionState).isIdle()

        rule.mainClock.autoAdvance = false

        // Start again and commit it.
        rule.runOnUiThread {
            dispatcher.dispatchOnBackStarted(backEvent())
            dispatcher.dispatchOnBackProgressed(backEvent(progress = 0.4f))
            dispatcher.onBackPressed()
        }
        rule.mainClock.advanceTimeByFrame()
        rule.waitForIdle()
        val transition2 = assertThat(layoutState.transitionState).isTransition()
        // verify that transition picks up progress from preview
        assertThat(transition2).hasProgress(0.4f, tolerance = 0.0001f)

        rule.mainClock.advanceTimeByFrame()
        rule.waitForIdle()
        // verify that transition is half way between preview-end-state (0.4f) and target-state (1f)
        // after one frame
        assertThat(transition2).hasProgress(0.7f, tolerance = 0.0001f)

        rule.mainClock.autoAdvance = true
        rule.waitForIdle()
        assertThat(layoutState.transitionState).hasCurrentScene(SceneB)
        assertThat(layoutState.transitionState).isIdle()