Check for null ItemInfo when reordering

This commit is contained in:
vfsfitvnm 2022-10-07 12:02:16 +02:00
parent a45270c54a
commit 3364bb9f30

View file

@ -59,7 +59,7 @@ class ReorderingState(
overscrolled = 0 overscrolled = 0
itemInfo = lazyListState.layoutInfo.visibleItemsInfo.find { itemInfo = lazyListState.layoutInfo.visibleItemsInfo.find {
it.index == index + extraItemCount it.index == index + extraItemCount
}!! } ?: return
onDragStart.invoke() onDragStart.invoke()
draggingIndex = index draggingIndex = index
reachedIndex = index reachedIndex = index
@ -83,6 +83,7 @@ class ReorderingState(
} }
fun onDrag(change: PointerInputChange, dragAmount: Offset) { fun onDrag(change: PointerInputChange, dragAmount: Offset) {
if (!isDragging) return
change.consume() change.consume()
val delta = when (lazyListState.layoutInfo.orientation) { val delta = when (lazyListState.layoutInfo.orientation) {
@ -163,6 +164,8 @@ class ReorderingState(
} }
fun onDragEnd() { fun onDragEnd() {
if (!isDragging) return
coroutineScope.launch { coroutineScope.launch {
offset.animateTo((previousItemSize + nextItemSize) / 2) offset.animateTo((previousItemSize + nextItemSize) / 2)