Custom Lazy Grid list lags

19 views Asked by At

I want to create custom implementation of LazyVerticalGrid. I've already done it but the scrolling list exhibits slight intermittent interruptions during movement. I can't see any additional recomposition. Is something wrong with my code?

  Data class Item(val name: String)

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val itemList = mutableListOf<Item>()
        repeat(520) { itemList.add(Item("Item ${it + 1}")) }
        val chunked = itemList.chunked(2)

        setContent {
            PixaBayApiTheme {
                LazyColumn(Modifier.fillMaxWidth()) {
                   listScope(chunked)
                }
            }
        }
    }
}

private fun LazyListScope.listScope(itemList: List<List<Item>>) {
    itemsIndexed(itemList, key = { index, list -> list.hashCode() }
    ) {index, sublist ->
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight()
        ) {
            sublist.fastForEach {
                ItemLayout(id = it.name)
            }
        }
    }
}



@Composable
fun ItemLayout(id: String) {
    Row(
        modifier = Modifier.height(80.dp),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.Start
    ) {
        Text(
            text = "lorem ipsum ${id}",
            maxLines = 2,
            overflow = TextOverflow.Ellipsis,
            modifier = Modifier.weight(1f, false)
        )

        Icon(
            imageVector = Icons.Default.AccountBox,
            contentDescription = "Account Box",
            modifier = Modifier.size(24.dp)
        )
    }
}
0

There are 0 answers