From 1d312a5acbabe48edfced233d0ae3eefce0caafb Mon Sep 17 00:00:00 2001 From: Calvin Liang Date: Sun, 12 May 2024 19:36:22 -0700 Subject: [PATCH] fix dragging second visible item scroll stuck --- .../reorderable/ReorderableLazyCollection.kt | 14 ++++++++++---- .../kotlin/sh/calvin/reorderable/Scroller.kt | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt index 2b45074..5216330 100644 --- a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt +++ b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt @@ -460,10 +460,16 @@ open class ReorderableLazyCollectionState internal constructor( // TODO(foundation v1.7.0): remove once foundation v1.7.0 is out val itemBeforeDraggingItem = visibleItems.getOrNull(visibleItems.indexOfFirst { it.key == draggingItemKey } - 1) - val itemToAlmostScrollOff = itemBeforeDraggingItem ?: it - - itemToAlmostScrollOff.offset.toOffset().getAxis(orientation) + + var itemToAlmostScrollOff = itemBeforeDraggingItem ?: it + var scrollDistance = itemToAlmostScrollOff.offset.toOffset().getAxis(orientation) + itemToAlmostScrollOff.size.getAxis(orientation) - 1f + if (scrollDistance <= 0f) { + itemToAlmostScrollOff = it + scrollDistance = itemToAlmostScrollOff.offset.toOffset().getAxis(orientation) + + itemToAlmostScrollOff.size.getAxis(orientation) - 1f + } + + scrollDistance }) ?: 0f }, onScroll = { @@ -802,7 +808,7 @@ internal class ReorderableCollectionItemScopeImpl( /** * A composable that allows items to be reordered by dragging. * - * @param state The return value of [rememberReorderableLazyCollectionState] + * @param state The return value of [rememberReorderableLazyListState], [rememberReorderableLazyGridState], or [rememberReorderableLazyStaggeredGridState] * @param key The key of the item, must be the same as the key passed to the parent composable * @param enabled Whether or this item is reorderable. If true, the item will not move for other items but may still be draggable. To make an item not draggable, set `enable = false` in [Modifier.draggable] or [Modifier.longPressDraggable] instead. * @param dragging Whether or not this item is currently being dragged diff --git a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/Scroller.kt b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/Scroller.kt index b7b006a..ef61e72 100644 --- a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/Scroller.kt +++ b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/Scroller.kt @@ -176,7 +176,7 @@ class Scroller internal constructor( if (!canScroll(direction)) break val maxScrollDistance = maxScrollDistanceProvider() - if (maxScrollDistance == 0f) { + if (maxScrollDistance <= 0f) { delay(ZeroScrollWaitDuration) continue }