Skip to content

Commit 23f2d4b

Browse files
authored
Merge pull request #4 from lcacheux/feature/onDragStart-callback
Add onDragStart callback
2 parents aa34c84 + c564163 commit 23f2d4b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ fun rememberReorderableLazyGridState(
3434
onMove: (ItemPosition, ItemPosition) -> Unit,
3535
gridState: LazyGridState = rememberLazyGridState(),
3636
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
37+
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
3738
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
3839
maxScrollPerFrame: Dp = 20.dp,
3940
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
4041
): ReorderableLazyGridState {
4142
val maxScroll = with(LocalDensity.current) { maxScrollPerFrame.toPx() }
4243
val scope = rememberCoroutineScope()
4344
val state = remember(gridState) {
44-
ReorderableLazyGridState(gridState, scope, maxScroll, onMove, canDragOver, onDragEnd, dragCancelledAnimation)
45+
ReorderableLazyGridState(gridState, scope, maxScroll, onMove, canDragOver, onDragStart, onDragEnd, dragCancelledAnimation)
4546
}
4647
LaunchedEffect(state) {
4748
state.visibleItemsChanged()
@@ -63,9 +64,10 @@ class ReorderableLazyGridState(
6364
maxScrollPerFrame: Float,
6465
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
6566
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
67+
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
6668
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
6769
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
68-
) : ReorderableState<LazyGridItemInfo>(scope, maxScrollPerFrame, onMove, canDragOver, onDragEnd, dragCancelledAnimation) {
70+
) : ReorderableState<LazyGridItemInfo>(scope, maxScrollPerFrame, onMove, canDragOver, onDragStart, onDragEnd, dragCancelledAnimation) {
6971
override val isVerticalScroll: Boolean
7072
get() = gridState.layoutInfo.orientation == Orientation.Vertical
7173
override val LazyGridItemInfo.left: Int

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ fun rememberReorderableLazyListState(
3838
onMove: (ItemPosition, ItemPosition) -> Unit,
3939
listState: LazyListState = rememberLazyListState(),
4040
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
41+
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
4142
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
4243
maxScrollPerFrame: Dp = 20.dp,
4344
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
4445
): ReorderableLazyListState {
4546
val maxScroll = with(LocalDensity.current) { maxScrollPerFrame.toPx() }
4647
val scope = rememberCoroutineScope()
4748
val state = remember(listState) {
48-
ReorderableLazyListState(listState, scope, maxScroll, onMove, canDragOver, onDragEnd, dragCancelledAnimation)
49+
ReorderableLazyListState(listState, scope, maxScroll, onMove, canDragOver, onDragStart, onDragEnd, dragCancelledAnimation)
4950
}
5051
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl
5152
LaunchedEffect(state) {
@@ -73,13 +74,15 @@ class ReorderableLazyListState(
7374
maxScrollPerFrame: Float,
7475
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
7576
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
77+
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
7678
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
7779
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
7880
) : ReorderableState<LazyListItemInfo>(
7981
scope,
8082
maxScrollPerFrame,
8183
onMove,
8284
canDragOver,
85+
onDragStart,
8386
onDragEnd,
8487
dragCancelledAnimation
8588
) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ abstract class ReorderableState<T>(
4141
private val maxScrollPerFrame: Float,
4242
private val onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
4343
private val canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)?,
44+
private val onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
4445
private val onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))?,
4546
val dragCancelledAnimation: DragCancelledAnimation
4647
) {
@@ -106,6 +107,7 @@ abstract class ReorderableState<T>(
106107
?.also {
107108
selected = it
108109
draggingItemIndex = it.itemIndex
110+
onDragStart?.invoke(it.itemIndex, offsetX, offsetY)
109111
} != null
110112
}
111113

0 commit comments

Comments
 (0)