Reputation: 55
I have a HorizontalPager for my main pages and inside one of them also nests another HorizontalPager. For implementing the infinite scrolling, I make
val pagerState = rememberPagerState(30) { Int.MAX_VALUE / 2 }
When I try pagerState.animateScrollToPage(nextPage)
, it cannot work.
More about my code:
LaunchedEffect(pagerState, isResumed) {
while (pagerState.pageCount > 1 && isResumed) {
delay(delayMillis)
val nextPage = (pagerState.currentPage + 1).coerceIn(0, pagerState.pageCount - 1)
Log.e("pager", "before current: ${pagerState.currentPage}, nextPage: $nextPage)
pagerState.animateScrollToPage(nextPage, animationSpec = tween(durationMillis = 1000))
Log.e("pager", "after current: ${pagerState.currentPage})
}
}
}
output log is:
before: current: 0, nextPage: 1
after: current: 0
before: current: 0, nextPage: 1
after: current: 0
...
compose-bom: 2024.05.00
Upvotes: 0
Views: 70
Reputation: 67149
As of Jetpack Compose 1.6.0 assigning big numbers as page count to create infinite Pagers causing ANRs. You need to keep pageCount as small as possible to prevent this issue.
Upvotes: 1