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

Commit 488cbd12 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid NPE when nested drag starts before enabling nestedDraggable()" into main

parents 4950e356 c1e7c48d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -549,9 +549,10 @@ private class NestedDraggableNode(
            nestedScrollController == null &&
                // TODO(b/388231324): Remove this.
                !lastEventWasScrollWheel &&
                draggable.shouldConsumeNestedScroll(sign)
                draggable.shouldConsumeNestedScroll(sign) &&
                lastFirstDown != null
        ) {
            val startedPosition = checkNotNull(lastFirstDown) { "lastFirstDown is not set" }
            val startedPosition = checkNotNull(lastFirstDown)

            // TODO(b/382665591): Ensure that there is at least one pointer down.
            val pointersDownCount = pointersDown.size.coerceAtLeast(1)
+23 −0
Original line number Diff line number Diff line
@@ -773,6 +773,29 @@ class NestedDraggableTest(override val orientation: Orientation) : OrientationAw
        rule.onNodeWithTag(buttonTag).assertTextEquals("Count: 3")
    }

    @Test
    fun nestedDragNotStartedWhenEnabledAfterDragStarted() {
        val draggable = TestDraggable()
        var enabled by mutableStateOf(false)
        val touchSlop =
            rule.setContentWithTouchSlop {
                Box(
                    Modifier.fillMaxSize()
                        .nestedDraggable(draggable, orientation, enabled = enabled)
                        .scrollable(rememberScrollableState { 0f }, orientation)
                )
            }

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

        enabled = true
        rule.waitForIdle()

        rule.onRoot().performTouchInput { moveBy((touchSlop + 1f).toOffset()) }

        assertThat(draggable.onDragStartedCalled).isFalse()
    }

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