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

Commit 2b08b992 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Handle cancellation in NestedDraggableNode.trackDownPosition()

This CL ensures that trackDownPosition() correctly clears the map of
pointersDown when the pointerInput is disabled.

Bug: 378470603
Test: atest NestedDraggableTest
Flag: EXEMPT NestedDraggable is not used yet
Change-Id: Ie3cd89b7622cc7cfbe7b28b9f24a23f783293a18
parent 9b4e15ea
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -459,6 +459,7 @@ private class NestedDraggableNode(

    private suspend fun PointerInputScope.trackDownPosition() {
        awaitEachGesture {
            try {
                val down = awaitFirstDown(requireUnconsumed = false)
                lastFirstDown = down.position
                pointersDown[down.id] = down.type
@@ -473,6 +474,9 @@ private class NestedDraggableNode(
                        }
                    }
                } while (pointersDown.size > 0)
            } finally {
                pointersDown.clear()
            }
        }
    }

+21 −0
Original line number Diff line number Diff line
@@ -689,6 +689,27 @@ class NestedDraggableTest(override val orientation: Orientation) : OrientationAw
        assertThat(draggable.onDragStartedPointerType).isEqualTo(PointerType.Mouse)
    }

    @Test
    fun pointersDown_clearedWhenDisabled() {
        val draggable = TestDraggable()
        var enabled by mutableStateOf(true)
        rule.setContent {
            Box(Modifier.fillMaxSize().nestedDraggable(draggable, orientation, enabled = enabled))
        }

        rule.onRoot().performTouchInput { down(center) }

        enabled = false
        rule.waitForIdle()

        rule.onRoot().performTouchInput { up() }

        enabled = true
        rule.waitForIdle()

        rule.onRoot().performTouchInput { down(center) }
    }

    private fun ComposeContentTestRule.setContentWithTouchSlop(
        content: @Composable () -> Unit
    ): Float {