Loading packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt +7 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,9 @@ class PriorityNestedScrollConnection( } override suspend fun onPreFling(available: Velocity): Velocity { // Note: This method may be called multiple times. Due to NestedScrollDispatcher, the order // of method calls (pre/post scroll/fling) cannot be guaranteed. if (isStopping) return Velocity.Zero val controller = currentController ?: return Velocity.Zero // If in priority mode and can stop on pre-fling phase, stop the scroll. Loading @@ -219,6 +222,9 @@ class PriorityNestedScrollConnection( } override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity { // Note: This method may be called multiple times. Due to NestedScrollDispatcher, the order // of method calls (pre/post scroll/fling) cannot be guaranteed. if (isStopping) return Velocity.Zero val availableFloat = available.toFloat() val controller = currentController Loading Loading @@ -315,6 +321,7 @@ class PriorityNestedScrollConnection( * @return The consumed velocity. */ suspend fun stop(velocity: Float): Velocity { if (isStopping) return Velocity.Zero val controller = requireController(isStopping = false) return coroutineScope { try { Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.compose.test.runMonotonicClockTest import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -262,4 +264,16 @@ class PriorityNestedScrollConnectionTest { scrollConnection.onPostFling(consumed = Velocity.Zero, available = Velocity.Zero) assertThat(isStarted).isEqualTo(true) } @Test fun handleMultipleOnPreFlingCalls() = runTest { startPriorityModePostScroll() coroutineScope { launch { scrollConnection.onPreFling(available = Velocity.Zero) } launch { scrollConnection.onPreFling(available = Velocity.Zero) } } assertThat(lastStop).isEqualTo(0f) } } Loading
packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt +7 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,9 @@ class PriorityNestedScrollConnection( } override suspend fun onPreFling(available: Velocity): Velocity { // Note: This method may be called multiple times. Due to NestedScrollDispatcher, the order // of method calls (pre/post scroll/fling) cannot be guaranteed. if (isStopping) return Velocity.Zero val controller = currentController ?: return Velocity.Zero // If in priority mode and can stop on pre-fling phase, stop the scroll. Loading @@ -219,6 +222,9 @@ class PriorityNestedScrollConnection( } override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity { // Note: This method may be called multiple times. Due to NestedScrollDispatcher, the order // of method calls (pre/post scroll/fling) cannot be guaranteed. if (isStopping) return Velocity.Zero val availableFloat = available.toFloat() val controller = currentController Loading Loading @@ -315,6 +321,7 @@ class PriorityNestedScrollConnection( * @return The consumed velocity. */ suspend fun stop(velocity: Float): Velocity { if (isStopping) return Velocity.Zero val controller = requireController(isStopping = false) return coroutineScope { try { Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.compose.test.runMonotonicClockTest import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -262,4 +264,16 @@ class PriorityNestedScrollConnectionTest { scrollConnection.onPostFling(consumed = Velocity.Zero, available = Velocity.Zero) assertThat(isStarted).isEqualTo(true) } @Test fun handleMultipleOnPreFlingCalls() = runTest { startPriorityModePostScroll() coroutineScope { launch { scrollConnection.onPreFling(available = Velocity.Zero) } launch { scrollConnection.onPreFling(available = Velocity.Zero) } } assertThat(lastStop).isEqualTo(0f) } }