Reputation: 31
I need to connect all the elements inside my LazyColumn to reset all the pinned states if I start changing one of them. Each one has elements for edit and delete behind it that I want to hide for all elements except the last one dragged. Also, I need to lock the movement for all elements except the active one. This is the easiest task, which I solved quickly.
I tried saving and resetting the active element's position, and then tracking the index and settledValue, but there are a lot of recompositions and sooner or later my statuses don't have enough time to update and the active element doesn't reset, which leaves all other elements blocked for dragging. And sometimes even the reset doesn't happen.
My anchors:
private sealed interface DragAnchors {
data object Start : DragAnchors
data object Center : DragAnchors
data object End : DragAnchors
}
Code to block parallel drags:
confirmValueChange = {
when (itemIndex) {
null -> {
if (it != DragAnchors.Center) itemIndex = index
true
}
rowIndex to index -> {
true
}
else -> {
false
}
}
}
Code to reset the current index:
LaunchedEffect(state.settledValue) {
if (itemIndex == index) itemIndex = null
}
Code to reset state if another item is active:
LaunchedEffect(itemIndex) {
if (itemIndex != null && itemIndex != rowIndex to index && state.targetValue != DragAnchors.Center)
state.snapTo(targetValue = DragAnchors.Center)
}
Upvotes: 2
Views: 214