Skip to content

Instantly share code, notes, and snippets.

View danielkvist's full-sized avatar

Daniel Kvist danielkvist

View GitHub Profile
@danielkvist
danielkvist / LongClickAndSwipeSelectable.kt
Created October 3, 2025 06:15
Long click and swipe to select multiple adjacent items in a LazyColumn or LazyRow in Compose.
/**
* Get info for the visible item at the given offset.
* Returns `null` if the offset does not correspond to an item.
*/
fun LazyListState.getVisibleItemInfoAtOffset(offset: Int): LazyListItemInfo? {
if (offset < layoutInfo.viewportStartOffset || offset > layoutInfo.viewportEndOffset) {
return null
}
for (item in layoutInfo.visibleItemsInfo) {
if (offset >= item.offset && offset < item.offset + item.size) {