Skip to content

Instantly share code, notes, and snippets.

@sergenes
Created June 21, 2021 16:35
Show Gist options
  • Save sergenes/2a0077c06fd9002a2f9ac5aeb6d0b61e to your computer and use it in GitHub Desktop.
Save sergenes/2a0077c06fd9002a2f9ac5aeb6d0b61e to your computer and use it in GitHub Desktop.
@Composable
fun HomeList(
editMode: Boolean,
items: SnapshotStateList<ListFile>,
clickItemHandler: (Int) -> Unit,
deleteItemHandler: (Int) -> Unit
) {
Column {
when (items.size) {
1 -> items.first().let {
HomeListItem(
it.fileName, it.created, RowType.SINGLE, editMode,
{ clickItemHandler(0) },
{ deleteItemHandler(0) }
)
}
else -> {
items.forEachIndexed { index, data ->
val rowType = when (index) {
0 -> RowType.TOP
items.lastIndex -> RowType.BOTTOM
else -> RowType.MIDDLE
}
HomeListItem(
data.fileName, data.created, rowType, editMode,
{ clickItemHandler(index) },
{ deleteItemHandler(index) }
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment