diff options
| author | 2024-11-12 15:10:34 +0000 | |
|---|---|---|
| committer | 2024-11-12 15:11:04 +0000 | |
| commit | 4fb4634292d72e6c00fdb87d1c97cd80431c2fc3 (patch) | |
| tree | 6a74231f22680ea3e757c63f23f1e40eb7ce5f17 | |
| parent | eed749f2e00802fb42837fa792b92f2b297c6a2b (diff) | |
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
2 files changed, 16 insertions, 9 deletions
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt index 20a0b390a037..3f182363e20c 100644 --- a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt +++ b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt @@ -365,12 +365,16 @@ private class OnStopScopeImpl(private val controller: ScrollController) : OnStop flingBehavior: FlingBehavior, ): Float { return with(flingBehavior) { - object : ScrollScope { - override fun scrollBy(pixels: Float): Float { - return controller.onScroll(pixels, NestedScrollSource.SideEffect) + val remainingVelocity = + object : ScrollScope { + override fun scrollBy(pixels: Float): Float { + return controller.onScroll(pixels, NestedScrollSource.SideEffect) + } } - } - .performFling(initialVelocity) + .performFling(initialVelocity) + + // returns the consumed velocity + initialVelocity - remainingVelocity } } } diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt index 91079b89a56c..28ea2d239b54 100644 --- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt +++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt @@ -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 |