Justin Xu
02/22/2023, 2:35 AMLazyColumn {
items() {
...
}
items() {
...
}
}
Where I want each items
to be surrounded by a Box
with a different color. How do I achieve this inside LazyListScope
?ephemient
02/22/2023, 2:40 AMJustin Xu
02/22/2023, 2:47 AMitems
block in the original question, and want to lazily load the items in each list. But if I need to do
item {
Box {
... items here ...
}
}
, would this lazily load everything inside the item
block at once then?ephemient
02/22/2023, 2:55 AMephemient
02/22/2023, 2:56 AMfun LazyListScope.columnItems(
count: Int,
backgroundColor: Color = Color.Unspecified,
paddingValues: PaddingValues = PaddingValues.Absolute(),
key: ((Int) -> Any)? = null,
contentType: (Int) -> Any? = { null },
itemContent: @Composable LazyItemScope.(index: Int) -> Unit
) {
if (count != 0) {
items(count = count, key = key, contentType = contentType) { index ->
val layoutDirection = LocalLayoutDirection.current
Box(
modifier = Modifier
.background(backgroundColor)
.fillParentMaxWidth()
.padding(
start = paddingValues.calculateStartPadding(layoutDirection),
top = if (index == 0) paddingValues.calculateTopPadding() else 0.dp,
end = paddingValues.calculateEndPadding(layoutDirection),
bottom = if (index == count - 1) paddingValues.calculateBottomPadding() else 0.dp
)
) {
itemContent(index)
}
}
} else {
item {
Box(modifier = Modifier.background(backgroundColor).fillParentMaxWidth().padding(paddingValues))
}
}
}
it'll look like a box containing all the items, without being a boxJustin Xu
02/22/2023, 3:15 AM