Skip to content

Commit

Permalink
Support for selected item in canDragOver
Browse files Browse the repository at this point in the history
  • Loading branch information
VeselyJan92 committed Oct 21, 2022
1 parent 3e0f386 commit 02bf5a7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ class ImageListViewModel : ViewModel() {
}
}

fun canDragOver(pos: ItemPosition) = images.any { it == pos.key }
fun canDragOver(draggedOver: ItemPosition, dragging: ItemPosition) = images.any { it == draggedOver.key }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ class ReorderListViewModel : ViewModel() {
}
}

fun isDogDragEnabled(pos: ItemPosition) = dogs.getOrNull(pos.index)?.isLocked != true
fun isDogDragEnabled(draggedOver: ItemPosition, dragging: ItemPosition) = dogs.getOrNull(draggedOver.index)?.isLocked != true
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import kotlinx.coroutines.CoroutineScope
fun rememberReorderableLazyGridState(
onMove: (ItemPosition, ItemPosition) -> Unit,
gridState: LazyGridState = rememberLazyGridState(),
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
maxScrollPerFrame: Dp = 20.dp,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
Expand Down Expand Up @@ -62,7 +62,7 @@ class ReorderableLazyGridState(
scope: CoroutineScope,
maxScrollPerFrame: Float,
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
) : ReorderableState<LazyGridItemInfo>(scope, maxScrollPerFrame, onMove, canDragOver, onDragEnd, dragCancelledAnimation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import kotlinx.coroutines.CoroutineScope
fun rememberReorderableLazyListState(
onMove: (ItemPosition, ItemPosition) -> Unit,
listState: LazyListState = rememberLazyListState(),
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
maxScrollPerFrame: Dp = 20.dp,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
Expand Down Expand Up @@ -72,7 +72,7 @@ class ReorderableLazyListState(
scope: CoroutineScope,
maxScrollPerFrame: Float,
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
canDragOver: ((index: ItemPosition) -> Boolean)? = null,
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
) : ReorderableState<LazyListItemInfo>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class ReorderableState<T>(
private val scope: CoroutineScope,
private val maxScrollPerFrame: Float,
private val onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
private val canDragOver: ((index: ItemPosition) -> Boolean)?,
private val canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)?,
private val onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))?,
val dragCancelledAnimation: DragCancelledAnimation
) {
Expand Down Expand Up @@ -203,7 +203,7 @@ abstract class ReorderableState<T>(
) {
return@fastForEach
}
if (canDragOver?.invoke(ItemPosition(item.itemIndex, item.itemKey)) != false) {
if (canDragOver?.invoke(ItemPosition(item.itemIndex, item.itemKey), ItemPosition(selected.itemIndex, selected.itemKey)) != false) {
val dx = (centerX - (item.left + item.right) / 2).absoluteValue
val dy = (centerY - (item.top + item.bottom) / 2).absoluteValue
val dist = dx * dx + dy * dy
Expand Down

0 comments on commit 02bf5a7

Please sign in to comment.