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

Commit ec55ee52 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Always return the remaining velocity after a fling

This CL slightly changes the logic in SwipeAnimation so that we always
return the velocity remaining after animating to the target offset, even
if the animation was done using a spring. This allows to still have a
slight overscroll when the spring is animating from a large offset, and
there is no reason not to have it as it arguably feels better.

Bug: 417444347
Test: Manual, noticed the slight overscroll even when not decaying
Flag: com.android.systemui.scene_container
Change-Id: I33ff9e134ec97dadb4f95d86709da9224c67065d
parent b6891b95
Loading
Loading
Loading
Loading
+34 −33
Original line number Diff line number Diff line
@@ -417,6 +417,7 @@ internal class SwipeAnimation<T : ContentKey>(
        // TODO(b/417444347): Use the default or fast spatial spec for small STLs, or make it a
        // parameter of the transitions spec.
        val animationSpec = spec ?: layoutState.motionScheme.slowSpatialSpec()
        val result =
            if (
                willDecayReachBounds &&
                    willDecayFasterThanAnimating(
@@ -427,7 +428,7 @@ internal class SwipeAnimation<T : ContentKey>(
                        initialVelocity,
                    )
            ) {
            val result = animatable.animateDecay(initialVelocity, decayAnimationSpec)
                animatable.animateDecay(initialVelocity, decayAnimationSpec).also { result ->
                    check(animatable.value == targetOffset) {
                        buildString {
                            appendLine(
@@ -439,21 +440,21 @@ internal class SwipeAnimation<T : ContentKey>(
                            appendLine("  decayOffset=$decayOffset")
                            appendLine(
                                "  animateDecay result: reason=${result.endReason} " +
                            "value=${result.endState.value} velocity=${result.endState.velocity}"
                                    "value=${result.endState.value} " +
                                    "velocity=${result.endState.velocity}"
                            )
                        }
                    }
            return initialVelocity - result.endState.velocity
                }

            } else {
                animatable.animateTo(
                    targetValue = targetOffset,
                    animationSpec = animationSpec,
                    initialVelocity = initialVelocity,
                )
            }

        // We consumed the whole velocity.
        return initialVelocity
        return initialVelocity - result.endState.velocity
    }

    private fun canChangeContent(targetContent: ContentKey): Boolean {