4

i want to scroll the view pager horizontally on button click in jetpack compose.Anyone have any idea about this ? Here i am using Accompanist library.

Jayant Kumar
  • 775
  • 5
  • 12

1 Answers1

15

You need to use pager state like this:

val state = rememberPagerState()
val scope = rememberCoroutineScope()
Button(onClick = {
    scope.launch {
        state.scrollToPage(state.currentPage + 1)
        // or 
        state.scrollBy(100f)
    }
}) {

}
VerticalPager(
    pagesCount,
    state = state
) { page ->

}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220