Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fun ComplexReorderableLazyColumnScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fun ComplexReorderableLazyRowScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fun SimpleLongPressHandleReorderableLazyColumnScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fun SimpleReorderableLazyColumnScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fun SimpleReorderableLazyHorizontalGridScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyHorizontalGrid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fun SimpleReorderableLazyHorizontalStaggeredGridScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyHorizontalStaggeredGrid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun SimpleReorderableLazyRowScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fun SimpleReorderableLazyVerticalGridScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyVerticalGrid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fun SimpleReorderableLazyVerticalStaggeredGridScreen() {
}

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyVerticalStaggeredGrid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fun TwoReorderableLazyColumnScreen() {
list2 = combinedList.slice(3..5)

haptic.performHapticFeedback(ReorderHapticFeedbackType.MOVE)
true
}

LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -257,7 +258,7 @@ enum class ScrollMoveMode {
open class ReorderableLazyCollectionState<out T> internal constructor(
private val state: LazyCollectionState<T>,
private val scope: CoroutineScope,
private val onMoveState: State<suspend CoroutineScope.(from: T, to: T) -> Unit>,
private val onMoveState: State<suspend CoroutineScope.(from: T, to: T) -> Boolean>,

/**
* The threshold in pixels for scrolling the list when dragging an item.
Expand Down Expand Up @@ -640,15 +641,15 @@ open class ReorderableLazyCollectionState<out T> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -160,7 +160,7 @@ private fun LazyGridState.toLazyCollectionState() =
class ReorderableLazyGridState internal constructor(
state: LazyGridState,
scope: CoroutineScope,
onMoveState: State<suspend CoroutineScope.(from: LazyGridItemInfo, to: LazyGridItemInfo) -> Unit>,
onMoveState: State<suspend CoroutineScope.(from: LazyGridItemInfo, to: LazyGridItemInfo) -> Boolean>,

/**
* The threshold in pixels for scrolling the grid when dragging an item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -246,7 +246,7 @@ private fun LazyListState.toLazyCollectionState() =
class ReorderableLazyListState internal constructor(
state: LazyListState,
scope: CoroutineScope,
onMoveState: State<suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Unit>,
onMoveState: State<suspend CoroutineScope.(from: LazyListItemInfo, to: LazyListItemInfo) -> Boolean>,

/**
* The threshold in pixels for scrolling the list when dragging an item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -159,7 +159,7 @@ private fun LazyStaggeredGridState.toLazyCollectionState() =
class ReorderableLazyStaggeredGridState internal constructor(
state: LazyStaggeredGridState,
scope: CoroutineScope,
onMoveState: State<suspend CoroutineScope.(from: LazyStaggeredGridItemInfo, to: LazyStaggeredGridItemInfo) -> Unit>,
onMoveState: State<suspend CoroutineScope.(from: LazyStaggeredGridItemInfo, to: LazyStaggeredGridItemInfo) -> Boolean>,

/**
* The threshold in pixels for scrolling the grid when dragging an item.
Expand Down