Skip to content

Commit 28ed78f

Browse files
authored
Merge pull request #184 from VeselyJan92/main
Support for selected item in canDragOver closes #180
2 parents dc60d65 + 02bf5a7 commit 28ed78f

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

android/src/main/kotlin/org/burnoutcrew/android/ui/reorderlist/ImageListViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ class ImageListViewModel : ViewModel() {
3333
}
3434
}
3535

36-
fun canDragOver(pos: ItemPosition) = images.any { it == pos.key }
36+
fun canDragOver(draggedOver: ItemPosition, dragging: ItemPosition) = images.any { it == draggedOver.key }
3737
}

android/src/main/kotlin/org/burnoutcrew/android/ui/reorderlist/ReorderListViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ class ReorderListViewModel : ViewModel() {
3939
}
4040
}
4141

42-
fun isDogDragEnabled(pos: ItemPosition) = dogs.getOrNull(pos.index)?.isLocked != true
42+
fun isDogDragEnabled(draggedOver: ItemPosition, dragging: ItemPosition) = dogs.getOrNull(draggedOver.index)?.isLocked != true
4343
}

reorderable/src/commonMain/kotlin/org/burnoutcrew/reorderable/ReorderableLazyGridState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import kotlinx.coroutines.CoroutineScope
3333
fun rememberReorderableLazyGridState(
3434
onMove: (ItemPosition, ItemPosition) -> Unit,
3535
gridState: LazyGridState = rememberLazyGridState(),
36-
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
36+
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
3737
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
3838
maxScrollPerFrame: Dp = 20.dp,
3939
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
@@ -62,7 +62,7 @@ class ReorderableLazyGridState(
6262
scope: CoroutineScope,
6363
maxScrollPerFrame: Float,
6464
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
65-
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
65+
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
6666
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
6767
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
6868
) : ReorderableState<LazyGridItemInfo>(scope, maxScrollPerFrame, onMove, canDragOver, onDragEnd, dragCancelledAnimation) {

reorderable/src/commonMain/kotlin/org/burnoutcrew/reorderable/ReorderableLazyListState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import kotlinx.coroutines.CoroutineScope
3737
fun rememberReorderableLazyListState(
3838
onMove: (ItemPosition, ItemPosition) -> Unit,
3939
listState: LazyListState = rememberLazyListState(),
40-
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
40+
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
4141
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
4242
maxScrollPerFrame: Dp = 20.dp,
4343
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
@@ -72,7 +72,7 @@ class ReorderableLazyListState(
7272
scope: CoroutineScope,
7373
maxScrollPerFrame: Float,
7474
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
75-
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
75+
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
7676
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
7777
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
7878
) : ReorderableState<LazyListItemInfo>(

reorderable/src/commonMain/kotlin/org/burnoutcrew/reorderable/ReorderableState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class ReorderableState<T>(
4040
private val scope: CoroutineScope,
4141
private val maxScrollPerFrame: Float,
4242
private val onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
43-
private val canDragOver: ((index: ItemPosition) -> Boolean)?,
43+
private val canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)?,
4444
private val onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))?,
4545
val dragCancelledAnimation: DragCancelledAnimation
4646
) {
@@ -205,7 +205,7 @@ abstract class ReorderableState<T>(
205205
) {
206206
return@fastForEach
207207
}
208-
if (canDragOver?.invoke(ItemPosition(item.itemIndex, item.itemKey)) != false) {
208+
if (canDragOver?.invoke(ItemPosition(item.itemIndex, item.itemKey), ItemPosition(selected.itemIndex, selected.itemKey)) != false) {
209209
val dx = (centerX - (item.left + item.right) / 2).absoluteValue
210210
val dy = (centerY - (item.top + item.bottom) / 2).absoluteValue
211211
val dist = dx * dx + dy * dy

0 commit comments

Comments
 (0)