Skip to content

Instantly share code, notes, and snippets.

@teegarcs
Created December 13, 2023 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teegarcs/4551676c62b1e0c060ff2cf1ab3e5d13 to your computer and use it in GitHub Desktop.
Save teegarcs/4551676c62b1e0c060ff2cf1ab3e5d13 to your computer and use it in GitHub Desktop.
Extension function genericList
fun <Intent : Any> LazyListScope.genericList(
items: List<GenericLazyItem<Intent>>,
processIntent: (Intent) -> Unit
) {
items.forEachIndexed { index, genericLazyItem ->
/*
Draw Header if the section is different than the previous one.
*/
if (index == 0 || genericLazyItem.sectionMatcher() != items[index - 1].sectionMatcher()) {
stickyHeader {
genericLazyItem.BuildHeaderItem(processIntent = processIntent)
}
}
/*
Calls the BuildItem function and provides the process Intent function.
*/
item(
key = genericLazyItem.itemKey(),
contentType = genericLazyItem::class
) {
genericLazyItem.BuildItem(processIntent = processIntent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment