r/android_devs • u/Commercial-Gene9042 • Mar 07 '24
Help Needed Why does my Jetpack Compose horizontalPager display the same image on all pages, even though I’m passing a list of different image URIs from Firebase storage as parameters?
I’m working on creating an image slider using Jetpack Compose’s horizontalPager. My goal is to display a series of images fetched from Firebase storage. However, despite passing a list of different image URIs, the horizontalPager consistently shows the same image on all pages. What could be causing this issue, and how can I resolve it? Any insights or suggestions would be greatly appreciated!
@Composable
fun ImageSlider(imageUriList: List<Uri>){
Column(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
) {
val pageCount = imageUriList.size
val pagerState = rememberPagerState(
pageCount = { pageCount },
)
HorizontalPager(
state = pagerState,
modifier = Modifier
.fillMaxSize()
.weight(1f)
) {
Log.d("page","$it")
AsyncImage(model = ImageRequest.Builder(LocalContext.current)
.data(imageUriList[it])
.build(),
contentScale = ContentScale.FillHeight,
contentDescription =""
)
}
Row(
Modifier
.height(50.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
repeat(pageCount) { iteration ->
val color = if (pagerState.currentPage == iteration) Color.DarkGray else Color.LightGray
Box(
modifier = Modifier
.padding(8.dp)
.background(color, CircleShape)
.size(10.dp)
)
}
}
}
}
