Skip to content

Commit

Permalink
Merge branch 'hotfix/dragAndDrop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Jul 6, 2023
2 parents b58fdce + e9103f6 commit 576df9d
Showing 1 changed file with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ class DragDropState internal constructor(
draggingItem.index != item.index
}
if (targetItem != null) {
val scrollToIndex = when {
targetItem.index == state.firstVisibleItemIndex -> draggingItem.index
draggingItem.index == state.firstVisibleItemIndex -> targetItem.index
else -> null
val scrollToIndex = if (targetItem.index == state.firstVisibleItemIndex) {
draggingItem.index
} else if (draggingItem.index == state.firstVisibleItemIndex) {
targetItem.index
} else {
null
}
if (scrollToIndex != null) {
scope.launch {
Expand Down Expand Up @@ -172,7 +174,7 @@ fun Modifier.dragContainer(dragDropState: DragDropState): Modifier {
}
}

@ExperimentalFoundationApi
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun LazyItemScope.DraggableItem(
dragDropState: DragDropState,
Expand All @@ -181,22 +183,19 @@ fun LazyItemScope.DraggableItem(
content: @Composable ColumnScope.(isDragging: Boolean) -> Unit
) {
val dragging = index == dragDropState.draggingItemIndex
val draggingModifier = when {
dragging -> {
Modifier
.zIndex(1f)
.graphicsLayer {
translationY = dragDropState.draggingItemOffset
}
}
index == dragDropState.previousIndexOfDraggedItem -> {
Modifier
.zIndex(1f)
.graphicsLayer {
translationY = dragDropState.previousItemOffset.value
}
}
else -> Modifier.animateItemPlacement()
val draggingModifier = if (dragging) {
Modifier
.zIndex(1f)
.graphicsLayer {
translationY = dragDropState.draggingItemOffset
}
} else if (index == dragDropState.previousIndexOfDraggedItem) {
Modifier.zIndex(1f)
.graphicsLayer {
translationY = dragDropState.previousItemOffset.value
}
} else {
Modifier.animateItemPlacement()
}
Column(modifier = modifier.then(draggingModifier)) {
content(dragging)
Expand Down

0 comments on commit 576df9d

Please sign in to comment.