Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created September 30, 2021 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmed-Sellami/6fdcc8840f903322762c9c12f438d487 to your computer and use it in GitHub Desktop.
Save Ahmed-Sellami/6fdcc8840f903322762c9c12f438d487 to your computer and use it in GitHub Desktop.
@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