1

I am facing high lags into my list. When scrolling it just feels so slow.

Here is my LazyGrid code

val images = // mutable List<Uri>
val state = rememberReorderableLazyGridState(onMove = { from, to ->
    images.add(to.index, images.removeAt(from.index))
})

LazyVerticalGrid(
    contentPadding = PaddingValues(
        bottom = 100.dp,
        start = 16.dp,
        end = 16.dp,
        top = 8.dp
    ),
    verticalArrangement = Arrangement.spacedBy(8.dp),
    horizontalArrangement = Arrangement.spacedBy(10.dp),
    columns = GridCells.Fixed(2),
    state = state.gridState,
    modifier = Modifier
        .reorderable(state)
        .detectReorderAfterLongPress(state)
        .fillMaxHeight()
        .alpha(if (creatingPdf.value) 0.5f else 1f),
    userScrollEnabled = creatingPdf.value.not()
) {
    items(images.size) { index ->
        val item = images[index]
        ReorderableItem(
            state,
            key = item,
            orientationLocked = false,
            index = index,
        ) { isDragging ->
            ElevatedCard(
                onClick = {
                    startCrop(index)
                },
                modifier = Modifier.shadow(
                    if (isDragging) 12.dp else 0.dp,
                    RoundedCornerShape(8.dp)
                ),
                enabled = creatingPdf.value.not()
            ) {
                Box {
                    AsyncImage(
                        model = item,
                        contentDescription = null,
                        contentScale = ContentScale.Crop,
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(230.dp),
                        alpha = if (isDragging) 0.8f else 1f,
                    )
                }
            }
        }
    }

I tried to remove Async Image and used normal Text but it still lags. So I think it has to do something with the state.

I also tried removing ReorderableItem but the problem still persists.

sanket kheni
  • 1,482
  • 2
  • 12
  • 29

0 Answers0