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

Commit a2653998 authored by Joshua Tsuji's avatar Joshua Tsuji
Browse files

Fix issue with left-flings when distanceToDestination = 0.

Test: atest SystemUITests
Change-Id: I96aaa6869713edfa9235fc858e193399e0301e30
parent 1093ceb6
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -293,15 +293,19 @@ class PhysicsAnimator<T> private constructor (val target: T) {
            val velocityToReachDestination = distanceToDestination *
                    (flingConfig.friction * FLING_FRICTION_SCALAR_MULTIPLIER)

            // Try to use the provided start velocity, but use the required velocity to reach the
            // destination if the provided velocity is insufficient.
            val sufficientVelocity =
                    if (distanceToDestination < 0)
                        min(velocityToReachDestination, startVelocity)
                    else
            // If there's distance to cover, and the provided velocity is moving in the correct
            // direction, ensure that the velocity is high enough to reach the destination.
            // Otherwise, just use startVelocity - this means that the fling is at or out of bounds.
            // The fling will immediately end and a spring will bring the object back into bounds
            // with this startVelocity.
            flingConfigCopy.startVelocity = when {
                distanceToDestination > 0f && startVelocity >= 0f ->
                    max(velocityToReachDestination, startVelocity)
                distanceToDestination < 0f && startVelocity <= 0f ->
                    min(velocityToReachDestination, startVelocity)
                else -> startVelocity
            }

            flingConfigCopy.startVelocity = sufficientVelocity
            springConfigCopy.finalPosition = toAtLeast
        } else {
            flingConfigCopy.startVelocity = startVelocity