I am using JetPack Compose Pager from Accompanist and I'm wonder how do I know exactly when my page is Showed at screen. Like onPageSelected method from ViewPager.
Here is my code:
HorizontalPager(
state = pagerState,
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colors.background)
) { page ->
// This method reinvoked many times.
}
'Cause currently each recomposition would invoke that callback method from Pager.
I think it will be better to use
LaunchedEffect(pagerState) {
snapshotFlow { pagerState.currentPage }.collect { page ->
// do your stuff with selected page
}
}