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

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

Merge "Fix the visibility threshold of BaseContentOverscrollEffect" into main

parents fa579dfd 1331d7ab
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.compose.gesture.effect

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.spring
import androidx.compose.foundation.OverscrollEffect
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.ui.geometry.Offset
@@ -46,7 +48,7 @@ open class BaseContentOverscrollEffect(
    private val animationSpec: AnimationSpec<Float>,
) : ContentOverscrollEffect {
    /** The [Animatable] that holds the current overscroll value. */
    private val animatable = Animatable(initialValue = 0f, visibilityThreshold = 0.5f)
    private val animatable = Animatable(initialValue = 0f)
    private var lastConverter: SpaceVectorConverter? = null

    override val overscrollDistance: Float
@@ -131,8 +133,26 @@ open class BaseContentOverscrollEffect(
            launch {
                val consumed = performFling(velocity)
                val remaining = velocity - consumed
                animatable.animateTo(0f, animationSpec, remaining.toFloat())
                animatable.animateTo(
                    0f,
                    animationSpec.withVisibilityThreshold(1f),
                    remaining.toFloat(),
                )
            }
        }
    }

    private fun <T> AnimationSpec<T>.withVisibilityThreshold(
        visibilityThreshold: T
    ): AnimationSpec<T> {
        return when (this) {
            is SpringSpec ->
                spring(
                    stiffness = stiffness,
                    dampingRatio = dampingRatio,
                    visibilityThreshold = visibilityThreshold,
                )
            else -> this
        }
    }