fix: improve drag-and-drop handling in ListsScreen by using a mutable state list for smoother animations

This commit is contained in:
2025-10-26 15:32:31 +01:00
parent 9b1cbccd03
commit 6b9f248adf
@@ -147,12 +147,15 @@ fun ListsScreen(
) )
} }
} else { } else {
// Maintain a working copy for smooth drag animations; commit to DB on drag end // Maintain a working list as a mutable state list for smoother edge animations
var working by remember { mutableStateOf(lists) } val working = remember { androidx.compose.runtime.mutableStateListOf<CollabList>() }
var dragging by remember { mutableStateOf(false) } var dragging by remember { mutableStateOf(false) }
// Keep working list in sync when not dragging // Keep working list in sync when not dragging
LaunchedEffect(lists, dragging) { LaunchedEffect(lists, dragging) {
if (!dragging) working = lists if (!dragging) {
working.clear()
working.addAll(lists)
}
} }
fun MutableList<CollabList>.move( fun MutableList<CollabList>.move(
@@ -168,10 +171,8 @@ fun ListsScreen(
rememberReorderableLazyListState( rememberReorderableLazyListState(
onMove = { from, to -> onMove = { from, to ->
dragging = true dragging = true
val newList = working.toMutableList() // Indices provided by reorderable correspond to draggable items only
// Indices provided by reorderable correspond to draggable items only (dividers ignored) working.move(from.index, to.index)
newList.move(from.index, to.index)
working = newList
}, },
onDragEnd = { _, _ -> onDragEnd = { _, _ ->
dragging = false dragging = false