Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created September 10, 2024 02:17
Show Gist options
  • Save skydoves/6117dadaa2ab39550a399bb54d14a4a8 to your computer and use it in GitHub Desktop.
Save skydoves/6117dadaa2ab39550a399bb54d14a4a8 to your computer and use it in GitHub Desktop.
consume_list_ui
@Composable
fun ConsumeList(
listUi: ListUi,
modifier: Modifier = Modifier,
) {
val layoutType = listUi.layout.toLayoutType()
when (layoutType) {
LayoutType.GRID -> {
LazyHorizontalGrid(
modifier = modifier
.fillMaxWidth()
.height(listUi.itemSize.heightDp()),
rows = GridCells.Adaptive(minSize = listUi.itemSize.widthDp()),
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
items(items = listUi.items, key = { it.url }) { imageUi ->
Box(
modifier = Modifier
.clip(RoundedCornerShape(8.dp))
.size(
width = listUi.itemSize.widthDp(),
height = listUi.itemSize.widthDp()
)
) {
ConsumeImageUi(
imageUi = imageUi.copy(size = listUi.itemSize),
)
}
}
}
}
LayoutType.COLUMN -> Unit // custom implementation
LayoutType.ROW -> Unit // custom implementation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment