Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created Sep 30, 2021
Embed
What would you like to do?
@ExperimentalAnimationApi
@Composable
fun ShoesCard(
shoesArticle: ShoesArticle,
slideState: SlideState,
shoesArticles: MutableList<ShoesArticle>,
updateSlideState: (shoesArticle: ShoesArticle, slideState: SlideState) -> Unit,
updateItemPosition: (currentIndex: Int, destinationIndex: Int) -> Unit
) {
val currentIndex = remember { mutableStateOf(0) }
val destinationIndex = remember { mutableStateOf(0) }
val isPlaced = remember { mutableStateOf(false) }
LaunchedEffect(isPlaced.value) {
if (isPlaced.value) {
if (currentIndex.value != destinationIndex.value) {
updateItemPosition(currentIndex.value, destinationIndex.value)
}
isPlaced.value = false
}
}
Box(
Modifier
.padding(horizontal = 16.dp)
.dragToReorder(
shoesArticle,
shoesArticles,
itemHeight,
updateSlideState,
{ isDragged.value = true },
{ cIndex, dIndex ->
isDragged.value = false
isPlaced.value = true
currentIndex.value = cIndex
destinationIndex.value = dIndex
}
)
.offset { IntOffset(0, verticalTranslation) }
.zIndex(zIndex)
.rotate(rotation)
) { /* ... */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment