Loading packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt +13 −2 Original line number Diff line number Diff line Loading @@ -519,8 +519,19 @@ internal class MultiPointerDraggableNode( // we intercept an ongoing swipe transition (i.e. startDragImmediately() returned // true). if (overSlop == 0f) { val delta = (drag.position - consumablePointer.position).toFloat() check(delta != 0f) { "delta is equal to 0" } // If the user drags in the opposite direction, the delta becomes zero because // we return to the original point. Therefore, we should use the previous event // to calculate the direction. val delta = (drag.position - drag.previousPosition).toFloat() check(delta != 0f) { buildString { append("delta is equal to 0 ") append("touchSlop ${currentValueOf(LocalViewConfiguration).touchSlop} ") append("consumablePointer.position ${consumablePointer.position} ") append("drag.position ${drag.position} ") append("drag.previousPosition ${drag.previousPosition}") } } overSlop = delta.sign } drag Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MultiPointerDraggableTest.kt +70 −3 Original line number Diff line number Diff line Loading @@ -593,7 +593,7 @@ class MultiPointerDraggableTest { } } fun continueDraggingDown() { fun dragDown() { rule.onRoot().performTouchInput { moveBy(Offset(0f, touchSlop)) } } Loading @@ -603,11 +603,78 @@ class MultiPointerDraggableTest { assertThat(started).isFalse() swipeConsume = true continueDraggingDown() // Drag in same direction dragDown() assertThat(capturedChange).isNotNull() capturedChange = null continueDraggingDown() dragDown() assertThat(capturedChange).isNull() assertThat(started).isTrue() } @Test fun multiPointerSwipeDetectorInteractionZeroOffsetFromStartPosition() { val size = 200f val middle = Offset(size / 2f, size / 2f) var started = false var capturedChange: PointerInputChange? = null var swipeConsume = false var touchSlop = 0f rule.setContent { touchSlop = LocalViewConfiguration.current.touchSlop Box( Modifier.size(with(LocalDensity.current) { Size(size, size).toDpSize() }) .nestedScrollDispatcher() .multiPointerDraggable( orientation = Orientation.Vertical, startDragImmediately = { false }, swipeDetector = object : SwipeDetector { override fun detectSwipe(change: PointerInputChange): Boolean { capturedChange = change return swipeConsume } }, onDragStarted = { _, _ -> started = true SimpleDragController( onDrag = { /* do nothing */ }, onStop = { /* do nothing */ }, ) }, dispatcher = defaultDispatcher, ) ) {} } fun startDraggingDown() { rule.onRoot().performTouchInput { down(middle) moveBy(Offset(0f, touchSlop)) } } fun dragUp() { rule.onRoot().performTouchInput { moveBy(Offset(0f, -touchSlop)) } } startDraggingDown() assertThat(capturedChange).isNotNull() capturedChange = null assertThat(started).isFalse() swipeConsume = true // Drag in the opposite direction dragUp() assertThat(capturedChange).isNotNull() capturedChange = null dragUp() assertThat(capturedChange).isNull() assertThat(started).isTrue() Loading Loading
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt +13 −2 Original line number Diff line number Diff line Loading @@ -519,8 +519,19 @@ internal class MultiPointerDraggableNode( // we intercept an ongoing swipe transition (i.e. startDragImmediately() returned // true). if (overSlop == 0f) { val delta = (drag.position - consumablePointer.position).toFloat() check(delta != 0f) { "delta is equal to 0" } // If the user drags in the opposite direction, the delta becomes zero because // we return to the original point. Therefore, we should use the previous event // to calculate the direction. val delta = (drag.position - drag.previousPosition).toFloat() check(delta != 0f) { buildString { append("delta is equal to 0 ") append("touchSlop ${currentValueOf(LocalViewConfiguration).touchSlop} ") append("consumablePointer.position ${consumablePointer.position} ") append("drag.position ${drag.position} ") append("drag.previousPosition ${drag.previousPosition}") } } overSlop = delta.sign } drag Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MultiPointerDraggableTest.kt +70 −3 Original line number Diff line number Diff line Loading @@ -593,7 +593,7 @@ class MultiPointerDraggableTest { } } fun continueDraggingDown() { fun dragDown() { rule.onRoot().performTouchInput { moveBy(Offset(0f, touchSlop)) } } Loading @@ -603,11 +603,78 @@ class MultiPointerDraggableTest { assertThat(started).isFalse() swipeConsume = true continueDraggingDown() // Drag in same direction dragDown() assertThat(capturedChange).isNotNull() capturedChange = null continueDraggingDown() dragDown() assertThat(capturedChange).isNull() assertThat(started).isTrue() } @Test fun multiPointerSwipeDetectorInteractionZeroOffsetFromStartPosition() { val size = 200f val middle = Offset(size / 2f, size / 2f) var started = false var capturedChange: PointerInputChange? = null var swipeConsume = false var touchSlop = 0f rule.setContent { touchSlop = LocalViewConfiguration.current.touchSlop Box( Modifier.size(with(LocalDensity.current) { Size(size, size).toDpSize() }) .nestedScrollDispatcher() .multiPointerDraggable( orientation = Orientation.Vertical, startDragImmediately = { false }, swipeDetector = object : SwipeDetector { override fun detectSwipe(change: PointerInputChange): Boolean { capturedChange = change return swipeConsume } }, onDragStarted = { _, _ -> started = true SimpleDragController( onDrag = { /* do nothing */ }, onStop = { /* do nothing */ }, ) }, dispatcher = defaultDispatcher, ) ) {} } fun startDraggingDown() { rule.onRoot().performTouchInput { down(middle) moveBy(Offset(0f, touchSlop)) } } fun dragUp() { rule.onRoot().performTouchInput { moveBy(Offset(0f, -touchSlop)) } } startDraggingDown() assertThat(capturedChange).isNotNull() capturedChange = null assertThat(started).isFalse() swipeConsume = true // Drag in the opposite direction dragUp() assertThat(capturedChange).isNotNull() capturedChange = null dragUp() assertThat(capturedChange).isNull() assertThat(started).isTrue() Loading