Accompanist Pager animateScrollToPage doesn't scroll to next page correctly

Viewed 46

Using accompanist-pager version 0.25.1, animateScrollToPage() doesn't seem to scroll all the way to make the next page fully visible, the previous page is still shown. The non animated version scrollToPage() seems to work fine however. Am I missing some additional params ?

@ExperimentalPagerApi
@Composable
fun MyPager() {
    val pagerState = rememberPagerState()
    HorizontalPager(
        count = 10,
        state = pagerState
    ) { pagerIndex ->
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(150.dp)
                .background(if (pagerIndex.mod(2) == 0) Color.Cyan else Color.Red)
        )
    }
    with(pagerState) {
        LaunchedEffect(key1 = currentPage) {
            launch {
                delay(10000)
                animateScrollToPage(
                    page = (currentPage + 1).mod(pageCount)
                )
            }
        }
    }
}

screenshot

1 Answers

I also had the same problem,In the end I chose to roll back the version of accompanist-pager to 0.24.1-alpha.

Related