Lists with LazyColumn
LazyColumn / LazyRow
They only compose items currently on screen, so they stay fast with thousands of rows.
@Composable
fun UserList(users: List<User>) {
LazyColumn(contentPadding = PaddingValues(12.dp)) {
items(users, key = { it.id }) { user ->
ListItem(
headlineContent = { Text(user.name) },
supportingContent = { Text(user.email) }
)
HorizontalDivider()
}
}
}
Grids
LazyVerticalGrid(columns = GridCells.Fixed(2)) {
items(photos) { photo -> PhotoCard(photo) }
}
Always pass a key so Compose can recycle and animate items correctly when the list changes.