-
-
Save Ahmed-Sellami/00a0bbd734412998c0a7450f13a2f0db 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
@ExperimentalAnimationApi | |
@Composable | |
fun Home() { | |
/* ... */ | |
Scaffold(/* ... */) { innerPadding -> | |
ShoesList( | |
modifier = Modifier.padding(innerPadding), | |
shoesArticles = shoesArticles, | |
slideStates = slideStates, | |
updateSlidedState = { shoesArticle, slideState -> slideStates[shoesArticle] = slideState }, | |
updateItemPosition = { currentIndex, destinationIndex -> | |
val shoesArticle = shoesArticles[currentIndex] | |
shoesArticles.removeAt(currentIndex) | |
shoesArticles.add(destinationIndex, shoesArticle) | |
slideStates.apply { | |
shoesArticles.map { shoesArticle -> | |
shoesArticle to SlideState.NONE | |
}.toMap().also { | |
putAll(it) | |
} | |
} | |
} | |
) | |
} | |
} | |
@ExperimentalAnimationApi | |
@Composable | |
fun ShoesList( | |
modifier: Modifier, | |
shoesArticles: MutableList<ShoesArticle>, | |
slideStates: Map<ShoesArticle, SlideState>, | |
updateSlidedState: (shoesArticle: ShoesArticle, slideState: SlideState) -> Unit, | |
updateItemPosition: (currentIndex: Int, destinationIndex: Int) -> Unit | |
) { | |
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, | |
shoesArticles = shoesArticles, | |
updateSlidedState = updateSlidedState, | |
updateItemPosition = updateItemPosition | |
) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment