Skip to content

Instantly share code, notes, and snippets.

@sergenes
Created June 21, 2021 16:36
Show Gist options
  • Select an option

  • Save sergenes/7ee58007bc7269dab4bed4b21c587aa2 to your computer and use it in GitHub Desktop.

Select an option

Save sergenes/7ee58007bc7269dab4bed4b21c587aa2 to your computer and use it in GitHub Desktop.
@Composable
fun HomeListLazy(
editMode: Boolean,
itemsSource: SnapshotStateList<ListFile>,
clickItemHandler: (Int) -> Unit,
deleteItemHandler: (Int) -> Unit
) {
LazyColumn {
when (itemsSource.size) {
1 -> itemsSource.first().let {
item {
HomeListItem(
it.fileName, it.created, RowType.SINGLE, editMode,
{ clickItemHandler(0) },
{ deleteItemHandler(0) }
)
}
}
else -> {
itemsIndexed(itemsSource) { index, item ->
val rowType = when (index) {
0 -> RowType.TOP
itemsSource.lastIndex -> RowType.BOTTOM
else -> RowType.MIDDLE
}
HomeListItem(
item.fileName, item.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