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

Commit 8006649e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "STL decay animation should only play if decayOffset exceeds targetOffset" into main

parents fb66a266 281126cf
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 +=