Skip to content

Instantly share code, notes, and snippets.

@Axrorxoja
Created February 23, 2024 18:22
Show Gist options
  • Save Axrorxoja/3e3c56237b08aa607e8aa2bd47490199 to your computer and use it in GitHub Desktop.
Save Axrorxoja/3e3c56237b08aa607e8aa2bd47490199 to your computer and use it in GitHub Desktop.
@Composable
fun ListItems(
modifier: Modifier = Modifier,
fastFiltersSelectDelegate: ItemsDelegate,
isAutoScroll: Boolean = false,
) {
val items by fastFiltersSelectDelegate.filterItems.collectAsStateWithLifecycle()
val listState = rememberLazyListState()
LazyRow(
modifier = Modifier
.fillMaxWidth()
.then(modifier),
state = listState
) {
items(items, ItemChipData::id) { item ->
ItemChip(
data = item,
modifier = Modifier.padding(horizontal = 2.dp, vertical = 4.dp),
onClick = fastFiltersSelectDelegate::onClickFilter,
)
}
}
if (isAutoScroll) {
LaunchedEffect(key1 = items) {
val selectedItem = items.indexOfFirst { it.isSelected }
if (selectedItem != -1) {
delay(200)//potensial problem
listState.animateScrollToItem(selectedItem)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment