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

Commit 80d63f34 authored by omarmt's avatar omarmt
Browse files

STL onStop remove dragController if needed

Fixes a bug introduced with ag/29700349.
This caused a crash (see ag/29996646) and for this reason it
has been reverted.

During onStop(), if a new drag controller appears, it signals the start
of a new gesture, so you can keep the new drag controller in place.

Test: atest DraggableHandlerTest
Bug: 370949877
Flag: com.android.systemui.scene_container
Change-Id: I84f108ba7130c80c844349f0ea7280bf755a62cf
parent 0dc3f705
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -743,8 +743,13 @@ internal class NestedScrollHandlerImpl(
                        .onStop(velocity = velocityAvailable, canChangeContent = canChangeScene)
                        .invoke()
                } finally {
                    // onStop might still be running when a new gesture begins.
                    // To prevent conflicts, we should only remove the drag controller if it's the
                    // same one that was active initially.
                    if (dragController == controller) {
                        dragController = null
                    }
                }
            },
            onCancel = {
                val controller = dragController ?: error("Should be called after onStart")
+28 −0
Original line number Diff line number Diff line
@@ -848,6 +848,34 @@ class DraggableHandlerTest {
        assertIdle(SceneB)
    }

    @Test
    fun duringATransition_aNewScrollGesture_shouldTakeControl() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        // First gesture
        nestedScroll.scroll(available = downOffset(fractionOfScreen = 0.1f))
        assertTransition(currentScene = SceneA)
        nestedScroll.preFling(available = Velocity.Zero)
        assertTransition(currentScene = SceneA)

        // Second gesture, it starts during onStop() animation
        nestedScroll.scroll(downOffset(0.1f))
        assertTransition(currentScene = SceneA)

        // Allows onStop() to complete or cancel
        advanceUntilIdle()

        // Second gesture continues
        nestedScroll.scroll(downOffset(0.1f))
        assertTransition(currentScene = SceneA)

        // Second gesture ends
        nestedScroll.preFling(available = Velocity.Zero)
        assertTransition(currentScene = SceneA)

        advanceUntilIdle()
        assertIdle(currentScene = SceneA)
    }

    @Test
    fun onPreFling_velocityLowerThanThreshold_remainSameScene() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)