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

Commit fb219458 authored by omarmt's avatar omarmt
Browse files

STL skipAnimation should depends on canChangeContent

We now check the conditions to skip the animation after computing the
current targetContent.
This helps avoid unexpected jump cut animations.

Test: atest DraggableHandlerTest
Test: manually test on Flexiglass
Bug: 382477212
Flag: com.android.systemui.scene_container
Change-Id: I1ccd6590867d8849b01cebf2d9dc1bcceb6d57f7
parent dc082200
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -337,13 +337,6 @@ internal class SwipeAnimation<T : ContentKey>(
        check(!isAnimatingOffset()) { "SwipeAnimation.animateOffset() can only be called once" }

        val initialProgress = progress
        // Skip the animation if we have already reached the target content and the overscroll does
        // not animate anything.
        val hasReachedTargetContent =
            (targetContent == toContent && initialProgress >= 1f) ||
                (targetContent == fromContent && initialProgress <= 0f)
        val skipAnimation =
            hasReachedTargetContent && !contentTransition.isWithinProgressRange(initialProgress)

        val targetContent =
            if (targetContent != currentContent && !canChangeContent(targetContent)) {
@@ -352,6 +345,14 @@ internal class SwipeAnimation<T : ContentKey>(
                targetContent
            }

        // Skip the animation if we have already reached the target content and the overscroll does
        // not animate anything.
        val hasReachedTargetContent =
            (targetContent == toContent && initialProgress >= 1f) ||
                (targetContent == fromContent && initialProgress <= 0f)
        val skipAnimation =
            hasReachedTargetContent && !contentTransition.isWithinProgressRange(initialProgress)

        val targetOffset =
            if (targetContent == fromContent) {
                0f
+22 −1
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import com.android.compose.animation.scene.content.state.TransitionState.Transit
import com.android.compose.animation.scene.subjects.assertThat
import com.android.compose.test.MonotonicClockTestScope
import com.android.compose.test.runMonotonicClockTest
import com.android.compose.test.transition
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
@@ -920,6 +919,28 @@ class DraggableHandlerTest {
        assertIdle(SceneA)
    }

    @Test
    fun blockTransition_animated() = runGestureTest {
        assertIdle(SceneA)
        layoutState.transitions = transitions { overscrollDisabled(SceneB, Orientation.Vertical) }

        // Swipe up to scene B. Overscroll 50%.
        val dragController = onDragStarted(overSlop = up(1.5f), expectedConsumedOverSlop = up(1.0f))
        assertTransition(currentScene = SceneA, fromScene = SceneA, toScene = SceneB, progress = 1f)

        // Block the transition when the user release their finger.
        canChangeScene = { false }
        val velocityConsumed =
            dragController.onDragStoppedAnimateLater(velocity = -velocityThreshold)

        // Start an animation: overscroll and from 1f to 0f.
        assertTransition(currentScene = SceneA, fromScene = SceneA, toScene = SceneB, progress = 1f)

        val consumed = velocityConsumed.await()
        assertThat(consumed).isEqualTo(-velocityThreshold)
        assertIdle(SceneA)
    }

    @Test
    fun scrollFromIdleWithNoTargetScene_shouldUseOverscrollSpecIfAvailable() = runGestureTest {
        layoutState.transitions = transitions {