Skip to content

Commit

Permalink
Fix snapping behavior (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkokoa committed Sep 12, 2024
1 parent 89a15f3 commit 2d5fc9c
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ internal fun WheelPicker(
}

private fun calculateSnappedItemIndex(lazyListState: LazyListState): Int {
var currentItemIndex = lazyListState.firstVisibleItemIndex
val currentItemIndex = lazyListState.firstVisibleItemIndex
val itemCount = lazyListState.layoutInfo.totalItemsCount
val offset = lazyListState.firstVisibleItemScrollOffset
val itemHeight = lazyListState.layoutInfo.visibleItemsInfo.firstOrNull()?.size ?: return currentItemIndex

if (lazyListState.firstVisibleItemScrollOffset != 0) {
currentItemIndex++
return if (offset > itemHeight / 2 && currentItemIndex < itemCount - 1) {
currentItemIndex + 1
} else {
currentItemIndex
}
return currentItemIndex
}

@Composable
Expand Down

0 comments on commit 2d5fc9c

Please sign in to comment.