From 3364bb9f30c0f156c43c5934a72a62e93770cc92 Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Fri, 7 Oct 2022 12:02:16 +0200 Subject: [PATCH] Check for null ItemInfo when reordering --- .../main/kotlin/it/vfsfitvnm/reordering/ReorderingState.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compose-reordering/src/main/kotlin/it/vfsfitvnm/reordering/ReorderingState.kt b/compose-reordering/src/main/kotlin/it/vfsfitvnm/reordering/ReorderingState.kt index d2b45f4..ff8f22e 100644 --- a/compose-reordering/src/main/kotlin/it/vfsfitvnm/reordering/ReorderingState.kt +++ b/compose-reordering/src/main/kotlin/it/vfsfitvnm/reordering/ReorderingState.kt @@ -59,7 +59,7 @@ class ReorderingState( overscrolled = 0 itemInfo = lazyListState.layoutInfo.visibleItemsInfo.find { it.index == index + extraItemCount - }!! + } ?: return onDragStart.invoke() draggingIndex = index reachedIndex = index @@ -83,6 +83,7 @@ class ReorderingState( } fun onDrag(change: PointerInputChange, dragAmount: Offset) { + if (!isDragging) return change.consume() val delta = when (lazyListState.layoutInfo.orientation) { @@ -163,6 +164,8 @@ class ReorderingState( } fun onDragEnd() { + if (!isDragging) return + coroutineScope.launch { offset.animateTo((previousItemSize + nextItemSize) / 2)