can you help to get rid of this jitter? code in th...
# compose
m
can you help to get rid of this jitter? code in thread
Copy code
@OptIn(ExperimentalPagerApi::class)
@Composable
fun GuideGallery(
    modifier: Modifier = Modifier,
    images: List<String>,
) {
    val pagerState = rememberPagerState(pageCount = images.size)
    val currentPage by snapshotFlow { pagerState.currentPage }.collectAsState(initial = 0)

    Column(
        modifier = modifier
            .fillMaxSize()
            .background(Color.Black),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        HorizontalPager(state = pagerState) { page ->
            Image(
                modifier = Modifier.fillMaxWidth(),
                painter = rememberCoilPainter(request = images[page]),
                contentScale = ContentScale.FillWidth,
                contentDescription = null,
            )
        }
        Spacer(modifier = Modifier.height(8.dp))
        Indicators(images.size, currentPage)
    }
}

@Composable
private fun Indicators(count: Int, selected: Int) {
    Row(horizontalArrangement = Arrangement.SpaceBetween) {
        repeat(count) { current ->
            DotIndicator(selected = current == selected)
        }
    }
}

@Composable
private fun DotIndicator(selected: Boolean) {
    val size by animateDpAsState(targetValue = if (selected) 12.dp else 8.dp)
    val color by animateColorAsState(targetValue = if (selected) Color.Magenta else Color.LightGray)
    Canvas(modifier = Modifier.size(12.dp)) {
        drawCircle(color, size.value)
    }
}
it’s accompanist
HorizontalPager
m
Try to explicitly set the size of the Image or at least it's aspect ratio
m
thanks. I will try