LazyDragSelectHorizontalGrid

fun <Item> LazyDragSelectHorizontalGrid(rows: GridCells, items: List<Item>, modifier: Modifier = Modifier, state: DragSelectState<Item> = rememberDragSelectState(), contentPadding: PaddingValues = PaddingValues(0.dp), reverseLayout: Boolean = false, horizontalArrangement: Arrangement.Horizontal = if (!reverseLayout) Arrangement.Start else Arrangement.End, verticalArrangement: Arrangement.Vertical = Arrangement.Top, flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(), userScrollEnabled: Boolean = true, enableAutoScroll: Boolean = true, autoScrollThreshold: Float? = null, enableHaptics: Boolean = true, hapticFeedback: HapticFeedback? = null, content: LazyDragSelectGridScope<Item>.() -> Unit)

A wrapper for LazyHorizontalGrid that provides drag selection functionality.

You can use LazyDragSelectGridItemScope.SelectableItem to wrap your item composable to make it selectable via a long press, or when selected via the drag-select.

Example usage:

@Composable
fun MyGrid() {
val items: List<Int> = List(100) { it }
val dragSelectState = rememberDragSelectState<Int>()

LazyDragSelectHorizontalGrid(
rows = GridCells.Adaptive(minSize = 128.dp),
items = items,
state = dragSelectState,
horizontalArrangement = Arrangement.spacedBy(3.dp),
verticalArrangement = Arrangement.spacedBy(3.dp),
) {
items { item ->
// SelectableItem is available on the grid scope
SelectableItem(item = item) { selected ->
// your item composable
}
}
}
}

Parameters

Item

The type of item in the grid.

rows

a class describing how cells form rows, see GridCells doc for more information.

modifier

the modifier to apply to this layout.

state

the state object to be used to control or observe the list's state.

contentPadding

specify a padding around the whole content.

reverseLayout

reverse the direction of scrolling and layout. When true, items will be laid out in the reverse order and LazyGridState.firstVisibleItemIndex == 0 means that grid is scrolled to the bottom. Note that reverseLayout does not change the behavior of verticalArrangement.

verticalArrangement

The vertical arrangement of the layout's children.

horizontalArrangement

The horizontal arrangement of the layout's children.

flingBehavior

logic describing fling behavior.

userScrollEnabled

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using the state even when it is disabled.

enableAutoScroll

whether to enable auto scroll when dragging outside of the grid.

autoScrollThreshold

the threshold in dp from the edge of the grid to start auto scroll.

enableHaptics

whether to enable haptic feedback when dragging outside of the grid.

hapticFeedback

the haptic feedback to be played when dragging outside of the grid.

content

the LazyGridScope which describes the content.

See also