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

Commit 281126cf authored by Omar Miatello's avatar Omar Miatello
Browse files

STL decay animation should only play if decayOffset exceeds targetOffset

This change also addresses sudden direction changes during fling.
The calculation to determine if the bound has been reached now only uses
targetOffset and decayOffset.

Test: atest DraggableHandlerTest
Bug: 388803469
Flag: com.android.systemui.scene_container
Change-Id: Ibaba56daee8081eb0d5ce66911f6e185aa416cc8
parent d3832f8b
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -403,11 +403,14 @@ internal class SwipeAnimation<T : ContentKey>(
                initialValue = initialOffset,
            )

        // The decay animation should only play if decayOffset exceeds targetOffset.
        val lowerBound = checkNotNull(animatable.lowerBound) { "No lower bound" }
        val upperBound = checkNotNull(animatable.upperBound) { "No upper bound" }
        val willDecayReachBounds =
            when {
                targetOffset > initialOffset -> decayOffset >= targetOffset
                targetOffset < initialOffset -> decayOffset <= targetOffset
                else -> true
            when (targetOffset) {
                lowerBound -> decayOffset <= lowerBound
                upperBound -> decayOffset >= upperBound
                else -> error("Target $targetOffset should be $lowerBound or $upperBound")
            }

        if (willDecayReachBounds) {
@@ -421,6 +424,10 @@ internal class SwipeAnimation<T : ContentKey>(
                    appendLine("  targetOffset=$targetOffset")
                    appendLine("  initialVelocity=$initialVelocity")
                    appendLine("  decayOffset=$decayOffset")
                    appendLine(
                        "  animateDecay result: reason=${result.endReason} " +
                            "value=${result.endState.value} velocity=${result.endState.velocity}"
                    )
                }
            }
            return initialVelocity - result.endState.velocity
+30 −0
Original line number Diff line number Diff line
@@ -772,6 +772,36 @@ class DraggableHandlerTest {
        assertThat(transition).hasProgress(1f)
    }

    @Test
    fun startSwipeAnimationFromBound() = runGestureTest {
        // Swipe down to go to SceneC.
        mutableUserActionsA = mapOf(Swipe.Down to SceneC)

        val dragController =
            onDragStarted(
                position = Offset(SCREEN_SIZE / 2f, SCREEN_SIZE / 2f),
                // Swipe up.
                overSlop = up(0.5f),
                // Should be ignored.
                expectedConsumedOverSlop = 0f,
            )

        val transition = assertThat(transitionState).isSceneTransition()
        assertThat(transition).hasFromScene(SceneA)
        assertThat(transition).hasToScene(SceneC)
        assertThat(transition).hasProgress(0f)

        // Swipe down, but not enough to go to SceneC.
        dragController.onDragStoppedAnimateNow(
            velocity = velocityThreshold - 0.01f,
            onAnimationStart = {
                assertTransition(fromScene = SceneA, toScene = SceneC, progress = 0f)
            },
        )

        assertIdle(SceneA)
    }

    @Test
    fun requireFullDistanceSwipe() = runGestureTest {
        mutableUserActionsA +=