Created
February 23, 2024 18:22
-
-
Save Axrorxoja/3e3c56237b08aa607e8aa2bd47490199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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