diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyColumnScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyColumnScreen.kt index 953d4f1..8b70382 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyColumnScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyColumnScreen.kt @@ -54,6 +54,7 @@ fun ComplexReorderableLazyColumnScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyColumn( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyRowScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyRowScreen.kt index 6f86b79..47b21f6 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyRowScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/ComplexReorderableLazyRowScreen.kt @@ -54,6 +54,7 @@ fun ComplexReorderableLazyRowScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyRow( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleLongPressHandleReorderableLazyColumnScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleLongPressHandleReorderableLazyColumnScreen.kt index b4d64ee..003b5ba 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleLongPressHandleReorderableLazyColumnScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleLongPressHandleReorderableLazyColumnScreen.kt @@ -46,6 +46,7 @@ fun SimpleLongPressHandleReorderableLazyColumnScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyColumn( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyColumnScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyColumnScreen.kt index f338d34..5a41b6d 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyColumnScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyColumnScreen.kt @@ -46,6 +46,7 @@ fun SimpleReorderableLazyColumnScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyColumn( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalGridScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalGridScreen.kt index 59f3307..659d2d5 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalGridScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalGridScreen.kt @@ -50,6 +50,7 @@ fun SimpleReorderableLazyHorizontalGridScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyHorizontalGrid( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalStaggeredGridScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalStaggeredGridScreen.kt index bcf8699..865221e 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalStaggeredGridScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyHorizontalStaggeredGridScreen.kt @@ -51,6 +51,7 @@ fun SimpleReorderableLazyHorizontalStaggeredGridScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyHorizontalStaggeredGrid( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyRowScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyRowScreen.kt index eb8dc3f..9b8f86f 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyRowScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyRowScreen.kt @@ -47,6 +47,7 @@ fun SimpleReorderableLazyRowScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyRow( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalGridScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalGridScreen.kt index 1117ba8..0cd4693 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalGridScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalGridScreen.kt @@ -50,6 +50,7 @@ fun SimpleReorderableLazyVerticalGridScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyVerticalGrid( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalStaggeredGridScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalStaggeredGridScreen.kt index af8ac0b..fdb8102 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalStaggeredGridScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/SimpleReorderableLazyVerticalStaggeredGridScreen.kt @@ -51,6 +51,7 @@ fun SimpleReorderableLazyVerticalStaggeredGridScreen() { } haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyVerticalStaggeredGrid( diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/TwoReorderableLazyColumnScreen.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/TwoReorderableLazyColumnScreen.kt index 8d4104b..af6ac99 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/TwoReorderableLazyColumnScreen.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/reorderable/demo/ui/TwoReorderableLazyColumnScreen.kt @@ -57,6 +57,7 @@ fun TwoReorderableLazyColumnScreen() { list2 = combinedList.slice(3..5) haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE) + true } LazyColumn( diff --git a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt index 74b16da..23444a9 100644 --- a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt +++ b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyCollection.kt @@ -62,6 +62,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withTimeout +import kotlin.time.Duration.Companion.milliseconds object ReorderableLazyCollectionDefaults { val ScrollThreshold = 48.dp @@ -257,7 +258,7 @@ enum class ScrollMoveMode { open class ReorderableLazyCollectionState internal constructor( private val state: LazyCollectionState, private val scope: CoroutineScope, - private val onMoveState: State Unit>, + private val onMoveState: State Boolean>, /** * The threshold in pixels for scrolling the list when dragging an item. @@ -640,15 +641,15 @@ open class ReorderableLazyCollectionState internal constructor( oldDraggingItemIndex = draggingItem.index - scope.(onMoveState.value)(draggingItem.data, targetItem.data) - - predictedDraggingItemOffset = if (targetItem.index > draggingItem.index) { - (targetItem.offset + targetItem.size) - draggingItem.size - } else { - targetItem.offset + if (scope.(onMoveState.value)(draggingItem.data, targetItem.data)) { + predictedDraggingItemOffset = if (targetItem.index > draggingItem.index) { + (targetItem.offset + targetItem.size) - draggingItem.size + } else { + targetItem.offset + } } - withTimeout(MoveItemsLayoutInfoUpdateMaxWaitDuration) { + withTimeout(MoveItemsLayoutInfoUpdateMaxWaitDuration.milliseconds) { // the first result from layoutInfoFlow is the current layoutInfo // the second result is the updated layoutInfo layoutInfoFlow.take(2).collect() diff --git a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyGrid.kt b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyGrid.kt index 7340621..42aa91f 100644 --- a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyGrid.kt +++ b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyGrid.kt @@ -67,7 +67,7 @@ fun rememberReorderableLazyGridState( pixelAmountProvider = { lazyGridState.layoutInfo.mainAxisViewportSize * ScrollAmountMultiplier }, ), scrollMoveMode: ScrollMoveMode = ScrollMoveMode.SWAP, - onMove: suspend CoroutineScope.(from: LazyGridItemInfo, to: LazyGridItemInfo) -> Unit, + onMove: suspend CoroutineScope.(from: LazyGridItemInfo, to: LazyGridItemInfo) -> Boolean, ): ReorderableLazyGridState { val density = LocalDensity.current val scrollThresholdPx = with(density) { scrollThreshold.toPx() } @@ -160,7 +160,7 @@ private fun LazyGridState.toLazyCollectionState() = class ReorderableLazyGridState internal constructor( state: LazyGridState, scope: CoroutineScope, - onMoveState: State Unit>, + onMoveState: State Boolean>, /** * The threshold in pixels for scrolling the grid when dragging an item. diff --git a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyList.kt b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyList.kt index b88d51c..6e3dca7 100644 --- a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyList.kt +++ b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyList.kt @@ -74,7 +74,7 @@ fun rememberReorderableLazyColumnState( scrollableState = lazyListState, pixelAmountProvider = { lazyListState.layoutInfo.mainAxisViewportSize * ScrollAmountMultiplier }, ), - onMove: suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Unit, + onMove: suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Boolean, ) = rememberReorderableLazyListState( lazyListState, scrollThresholdPadding, @@ -110,7 +110,7 @@ fun rememberReorderableLazyRowState( scrollableState = lazyListState, pixelAmountProvider = { lazyListState.layoutInfo.mainAxisViewportSize * ScrollAmountMultiplier }, ), - onMove: suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Unit, + onMove: suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Boolean, ) = rememberReorderableLazyListState( lazyListState, scrollThresholdPadding, @@ -139,7 +139,7 @@ fun rememberReorderableLazyListState( scrollableState = lazyListState, pixelAmountProvider = { lazyListState.layoutInfo.mainAxisViewportSize * ScrollAmountMultiplier }, ), - onMove: suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Unit, + onMove: suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Boolean, ): ReorderableLazyListState { val density = LocalDensity.current val scrollThresholdPx = with(density) { scrollThreshold.toPx() } @@ -246,7 +246,7 @@ private fun LazyListState.toLazyCollectionState() = class ReorderableLazyListState internal constructor( state: LazyListState, scope: CoroutineScope, - onMoveState: State Unit>, + onMoveState: State Boolean>, /** * The threshold in pixels for scrolling the list when dragging an item. diff --git a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyStaggeredGrid.kt b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyStaggeredGrid.kt index 310fb9d..8b4124e 100644 --- a/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyStaggeredGrid.kt +++ b/reorderable/src/commonMain/kotlin/sh/calvin/reorderable/ReorderableLazyStaggeredGrid.kt @@ -67,7 +67,7 @@ fun rememberReorderableLazyStaggeredGridState( pixelAmountProvider = { lazyStaggeredGridState.layoutInfo.mainAxisViewportSize * ScrollAmountMultiplier }, ), scrollMoveMode: ScrollMoveMode = ScrollMoveMode.SWAP, - onMove: suspend CoroutineScope.(from: LazyStaggeredGridItemInfo, to: LazyStaggeredGridItemInfo) -> Unit, + onMove: suspend CoroutineScope.(from: LazyStaggeredGridItemInfo, to: LazyStaggeredGridItemInfo) -> Boolean, ): ReorderableLazyStaggeredGridState { val density = LocalDensity.current val scrollThresholdPx = with(density) { scrollThreshold.toPx() } @@ -159,7 +159,7 @@ private fun LazyStaggeredGridState.toLazyCollectionState() = class ReorderableLazyStaggeredGridState internal constructor( state: LazyStaggeredGridState, scope: CoroutineScope, - onMoveState: State Unit>, + onMoveState: State Boolean>, /** * The threshold in pixels for scrolling the grid when dragging an item.