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

Commit 4fb46342 authored by omarmt's avatar omarmt
Browse files

STL flingToScroll should return the consumed velocity

flingToScroll() was introduced in ag/29700350.

We initially assumed that performFling() would return the consumed
velocity, as many other Compose APIs do. However, this particular
function returns the remaining velocity.

To ensure consistency, our flingToScroll function should also return the
consumed velocity. We have updated the test to reflect this expected
 behavior.

Test: atest PriorityNestedScrollConnection
Bug: 370949877
Flag: com.android.systemui.scene_container
Change-Id: I2fe883491a0681b72030b2b64493712d24867fc8
parent eed749f2
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -365,12 +365,16 @@ private class OnStopScopeImpl(private val controller: ScrollController) : OnStop
        flingBehavior: FlingBehavior,
    ): Float {
        return with(flingBehavior) {
            val remainingVelocity =
                object : ScrollScope {
                        override fun scrollBy(pixels: Float): Float {
                            return controller.onScroll(pixels, NestedScrollSource.SideEffect)
                        }
                    }
                    .performFling(initialVelocity)

            // returns the consumed velocity
            initialVelocity - remainingVelocity
        }
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ class PriorityNestedScrollConnectionTest {
        object : FlingBehavior {
            override suspend fun ScrollScope.performFling(initialVelocity: Float): Float {
                scrollBy(initialVelocity)
                return initialVelocity / 2f
                // returns the remaining velocity: 1/3 remained + 2/3 consumed
                return initialVelocity / 3f
            }
        }

@@ -207,11 +208,13 @@ class PriorityNestedScrollConnectionTest {

        val consumed = scrollConnection.onPreFling(available = Velocity(2f, 2f))

        assertThat(lastStop).isEqualTo(2f)
        val initialVelocity = 2f
        assertThat(lastStop).isEqualTo(initialVelocity)
        // flingToScroll should try to scroll the content, customFlingBehavior uses the velocity.
        assertThat(lastScroll).isEqualTo(2f)
        // customFlingBehavior returns half of the vertical velocity.
        assertThat(consumed).isEqualTo(Velocity(0f, 1f))
        val remainingVelocity = initialVelocity / 3f
        // customFlingBehavior returns 2/3 of the vertical velocity.
        assertThat(consumed).isEqualTo(Velocity(0f, initialVelocity - remainingVelocity))
    }

    @Test