How to react to to user scrolling on Accompanist Pager?

Viewed 23

The Accompanist Pager documentation suggests reacting to page changes as follows :

val pagerState = rememberPagerState()

LaunchedEffect(pagerState) {
    // Collect from the pager state a snapshotFlow reading the currentPage
    snapshotFlow { pagerState.currentPage }.collect { page ->
        AnalyticsService.sendPageSelectedEvent(page)
    }
}

VerticalPager(
    count = 10,
    state = pagerState,
) { page ->
    Text(text = "Page: $page")
}

How can we distinguish scrolling to a page from user gesture, and scrolling to a page using animateScrollingToPage() / scrollingToPage() ? I would like to perform a certain action only on user scroll, not on programmatic scroll.

0 Answers
Related