From a26539987c753c2c9aaa7aeaca4136149114760a Mon Sep 17 00:00:00 2001 From: Joshua Tsuji Date: Wed, 15 Jan 2020 14:28:38 -0500 Subject: [PATCH] Fix issue with left-flings when distanceToDestination = 0. Test: atest SystemUITests Change-Id: I96aaa6869713edfa9235fc858e193399e0301e30 --- .../util/animation/PhysicsAnimator.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt b/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt index d5a296f82969d..cfd77be9303dd 100644 --- a/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt +++ b/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt @@ -293,15 +293,19 @@ class PhysicsAnimator 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 - max(velocityToReachDestination, startVelocity) + // 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