Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created Sep 27, 2021
Embed
What would you like to do?
@ExperimentalAnimationApi
@Composable
fun Home() {
val slideStates = remember {
mutableStateMapOf<ShoesArticle, SlideState>()
.apply {
shoesArticles.map { shoesArticle ->
shoesArticle to SlideState.NONE
}.toMap().also {
putAll(it)
}
}
}
Scaffold(/* ... */) { innerPadding ->
ShoesList(
modifier = Modifier.padding(innerPadding),
shoesArticles = shoesArticles,
slideStates = slideStates
)
}
}
@ExperimentalAnimationApi
@Composable
fun ShoesList(
modifier: Modifier,
shoesArticles: MutableList<ShoesArticle>,
slideStates: Map<ShoesArticle, SlideState>
) {
val lazyListState = rememberLazyListState()
LazyColumn(
state = lazyListState,
modifier = modifier.padding(top = dimensionResource(id = R.dimen.list_top_padding))
) {
items(shoesArticles.size) { index ->
val shoesArticle = shoesArticles.getOrNull(index)
if (shoesArticle != null) {
key(shoesArticle) {
val slideState = slideStates[shoesArticle] ?: SlideState.NONE
ShoesCard(
shoesArticle = shoesArticle,
slideState = slideState
)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment