Skip to content
Merged
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 @@ -34,14 +34,15 @@ fun rememberReorderableLazyGridState(
onMove: (ItemPosition, ItemPosition) -> Unit,
gridState: LazyGridState = rememberLazyGridState(),
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
maxScrollPerFrame: Dp = 20.dp,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
): ReorderableLazyGridState {
val maxScroll = with(LocalDensity.current) { maxScrollPerFrame.toPx() }
val scope = rememberCoroutineScope()
val state = remember(gridState) {
ReorderableLazyGridState(gridState, scope, maxScroll, onMove, canDragOver, onDragEnd, dragCancelledAnimation)
ReorderableLazyGridState(gridState, scope, maxScroll, onMove, canDragOver, onDragStart, onDragEnd, dragCancelledAnimation)
}
LaunchedEffect(state) {
state.visibleItemsChanged()
Expand All @@ -63,9 +64,10 @@ class ReorderableLazyGridState(
maxScrollPerFrame: Float,
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
) : ReorderableState<LazyGridItemInfo>(scope, maxScrollPerFrame, onMove, canDragOver, onDragEnd, dragCancelledAnimation) {
) : ReorderableState<LazyGridItemInfo>(scope, maxScrollPerFrame, onMove, canDragOver, onDragStart, onDragEnd, dragCancelledAnimation) {
override val isVerticalScroll: Boolean
get() = gridState.layoutInfo.orientation == Orientation.Vertical
override val LazyGridItemInfo.left: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ fun rememberReorderableLazyListState(
onMove: (ItemPosition, ItemPosition) -> Unit,
listState: LazyListState = rememberLazyListState(),
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
maxScrollPerFrame: Dp = 20.dp,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
): ReorderableLazyListState {
val maxScroll = with(LocalDensity.current) { maxScrollPerFrame.toPx() }
val scope = rememberCoroutineScope()
val state = remember(listState) {
ReorderableLazyListState(listState, scope, maxScroll, onMove, canDragOver, onDragEnd, dragCancelledAnimation)
ReorderableLazyListState(listState, scope, maxScroll, onMove, canDragOver, onDragStart, onDragEnd, dragCancelledAnimation)
}
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl
LaunchedEffect(state) {
Expand Down Expand Up @@ -73,13 +74,15 @@ class ReorderableLazyListState(
maxScrollPerFrame: Float,
onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)? = null,
onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))? = null,
dragCancelledAnimation: DragCancelledAnimation = SpringDragCancelledAnimation()
) : ReorderableState<LazyListItemInfo>(
scope,
maxScrollPerFrame,
onMove,
canDragOver,
onDragStart,
onDragEnd,
dragCancelledAnimation
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ abstract class ReorderableState<T>(
private val maxScrollPerFrame: Float,
private val onMove: (fromIndex: ItemPosition, toIndex: ItemPosition) -> (Unit),
private val canDragOver: ((draggedOver: ItemPosition, dragging: ItemPosition) -> Boolean)?,
private val onDragStart: ((startIndex: Int, x: Int, y: Int) -> (Unit))? = null,
private val onDragEnd: ((startIndex: Int, endIndex: Int) -> (Unit))?,
val dragCancelledAnimation: DragCancelledAnimation
) {
Expand Down Expand Up @@ -105,6 +106,7 @@ abstract class ReorderableState<T>(
?.also {
selected = it
draggingItemIndex = it.itemIndex
onDragStart?.invoke(it.itemIndex, offsetX, offsetY)
} != null
}

Expand Down