Skip to content

Commit

Permalink
fix dragging second visible item scroll stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin-LL committed May 13, 2024
1 parent 3b68632 commit 1d312a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,16 @@ open class ReorderableLazyCollectionState<out T> 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 = {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Scroller internal constructor(
if (!canScroll(direction)) break

val maxScrollDistance = maxScrollDistanceProvider()
if (maxScrollDistance == 0f) {
if (maxScrollDistance <= 0f) {
delay(ZeroScrollWaitDuration)
continue
}
Expand Down

0 comments on commit 1d312a5

Please sign in to comment.