Describe the bug
LazyList with snapper doesn't scroll to the item defined by initialFirstVisibleItemIndex
.
To Reproduce
Steps to reproduce the behavior:
val lazyListState = rememberLazyListState(initialFirstVisibleItemIndex = 3)
val flingBehavior = rememberSnapperFlingBehavior(
lazyListState = lazyListState,
endContentPadding = contentPadding.calculateEndPadding(LayoutDirection.Ltr),
)
LazyRow(
state = lazyListState,
flingBehavior = flingBehavior
) {
items(5) {
// show item here
}
}
Expected behavior
On the initial display (or first launch), the lazylist should auto-scroll to 3rd item. The lazylist shouldn't scroll after display but rather scroll to the correct initial item index before displaying.
Actual behavior
On initial display, the lazylist shows 1st item as the 1st visible item.
To work this issue around, I am using a side affect to scroll to the initial page when the screen is shown
val lazyListState = rememberLazyListState(initialFirstVisibleItemIndex = 3)
// workaround
LaunchedEffect(Unit) {
lazyListState.animateScrollToItem(initialPage)
}
val flingBehavior = rememberSnapperFlingBehavior(
lazyListState = lazyListState,
endContentPadding = contentPadding.calculateEndPadding(LayoutDirection.Ltr),
)
LazyRow(
state = lazyListState,
flingBehavior = flingBehavior
) {
items(5) {
// show item here
}
}
Screenshots?
If applicable, add screenshots to help explain your problem.
Environment:
- Android OS version: 13
- Device: Google Pixel 4a
- Library version: 0.2.2
Additional context
Add any other context about the problem here.
Stale