1 year ago
#326434
SpiralDev
OffscreenPageLimit behaviour for ViewPager from Accompanist
I am using HorizontalViewPager from Accompanist to show an image in each page of the viewpager. I am loading images with Coil. Here's the code:
val pagerState = rememberPagerState()
HorizontalPager(count = photos.size, state = pagerState) {
idx ->
photos[idx].let { cur ->
Image(
painter = rememberImagePainter(url),
contentDescription = null,
modifier - Modifier.fillMaxSize(),
contentScale = ContentScale.FillHeight,
alignment = Alignment.Center
)
}
}
It is working fine. But, Images are being loaded only after the page is opened. I was wondering if there is a way to preload the content of the adjacent pages of viewpager before they are opened.
ViewPager from AndroidX offers similar behavior with setOffscreenPageLimit
method.
android
android-viewpager
android-jetpack-compose
jetpack-compose-accompanist
0 Answers
Your Answer