I am trying to update the stikcyHeader
composable while the list is scrolling based on some criteria about number of items being displayed in given section (i.e under one header). I can't figure out a way to do that. Here's what the code looks like.
data class Group(
val title: String,
val items: List<Item>
)
data class Item(
val label: String,
val subItems: List<SubItem> = emptyList()
)
data class SubItem(val id: String)
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun StickyList(groups: List<Group>) {
val listState = rememberLazyListState()
LazyColumn(state = listState, modifier = Modifier.fillMaxWidth()) {
groups.forEach { group ->
val subItemId = mutableStateOf("")
stickyHeader {
Row(
Modifier
.background(Color.LightGray)
.padding(16.dp)
) {
if (subItemId.value.isNotBlank()) {
Text(
text = "Item label: ${subItemId.value}",
Modifier.padding(horizontal = 8.dp)
)
}
Text(
text = group.title,
Modifier
.weight(1f)
)
}
}
group.items.forEach { item ->
item {
Column {
Text(text = "Item : ${item.label}", Modifier.padding(16.dp))
item.subItems.forEach { subItem ->
Text(text = "Sub Item id : ${subItem.id}", Modifier.padding(8.dp))
}
Divider()
if (item.subItems.size > 5) {
subItemId.value = item.label
}
}
}
}
}
}
}
What I'm trying to achieve is to display subItemId
value on a the stickyHeader
only if the number of subItems
in the item
that is currently at the top of the list is more than 5.
I can't find any pointers if I can use LazyListLayoutInfo
from LazyListState
to achieve this. I'd appreciate any help. Thanks.