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

Commit de7b75b4 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

Ensure screenshot dismissal velocity is never 0

It's possible to get a value of 0 passed in to the dismissal animation,
which isn't handled correctly when attempting to set a minimum velocity.
This change fixes the minimum velocity calculation so it is correct even
if the input is 0f.

Bug: 362859928
Fix: 362859928
Test: manual. invoke screenshots, move screenshot UI and let it return
to its original location, then move it out again and move pointer
straight up and release. screenshot should dismiss normally without
getting 'stuck'.
Flag: EXEMPT trivial fix

Change-Id: Idc963cf322d11be007b5e9167e783c7a2661a03b
parent 20f915ec
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import kotlin.math.sign

class ScreenshotAnimationController(
    private val view: ScreenshotShelfView,
    private val viewModel: ScreenshotViewModel
    private val viewModel: ScreenshotViewModel,
) {
    private var animator: Animator? = null
    private val screenshotPreview = view.requireViewById<ImageView>(R.id.screenshot_preview)
@@ -56,7 +56,7 @@ class ScreenshotAnimationController(
        listOf<View>(
            view.requireViewById(R.id.screenshot_preview_border),
            view.requireViewById(R.id.screenshot_badge),
            view.requireViewById(R.id.screenshot_dismiss_button)
            view.requireViewById(R.id.screenshot_dismiss_button),
        )
    private val fadeUI =
        listOf<View>(
@@ -70,7 +70,7 @@ class ScreenshotAnimationController(
    fun getEntranceAnimation(
        bounds: Rect,
        showFlash: Boolean,
        onRevealMilestone: () -> Unit
        onRevealMilestone: () -> Unit,
    ): Animator {
        val entranceAnimation = AnimatorSet()

@@ -142,7 +142,7 @@ class ScreenshotAnimationController(
    fun runLongScreenshotTransition(
        destRect: Rect,
        longScreenshot: ScrollCaptureController.LongScreenshot,
        onTransitionEnd: Runnable
        onTransitionEnd: Runnable,
    ): Animator {
        val animSet = AnimatorSet()

@@ -165,7 +165,7 @@ class ScreenshotAnimationController(
            matrix.setScale(currentScale, currentScale)
            matrix.postTranslate(
                longScreenshot.left * currentScale,
                longScreenshot.top * currentScale
                longScreenshot.top * currentScale,
            )
            scrollTransitionPreview.setImageMatrix(matrix)
            val destinationScale: Float = destRect.width() / scrollTransitionPreview.width.toFloat()
@@ -315,7 +315,7 @@ class ScreenshotAnimationController(
    }

    private fun getAdjustedVelocity(requestedVelocity: Float?): Float {
        return if (requestedVelocity == null) {
        return if (requestedVelocity == null || abs(requestedVelocity) < .005f) {
            val isLTR = view.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR
            // dismiss to the left in LTR locales, to the right in RTL
            if (isLTR) -MINIMUM_VELOCITY else MINIMUM_VELOCITY
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import kotlin.math.abs
class SwipeGestureListener(
    private val view: View,
    private val onDismiss: (Float?) -> Unit,
    private val onCancel: () -> Unit
    private val onCancel: () -> Unit,
) {
    private val velocityTracker = VelocityTracker.obtain()
    private val displayMetrics = view.resources.displayMetrics
@@ -54,9 +54,9 @@ class SwipeGestureListener(
                    onDismiss.invoke(xVelocity)
                    return true
                } else {
                    velocityTracker.clear()
                    onCancel.invoke()
                }
                velocityTracker.clear()
            }
            MotionEvent.ACTION_MOVE -> {
                velocityTracker.addMovement(ev)