Reorderable icon indicating copy to clipboard operation
Reorderable copied to clipboard

Column appears to recompose before list is re-ordered

Open gdude2002 opened this issue 8 months ago • 5 comments

Using the code available here (which I based on your demo project, without the haptics)

When reordering items in this relatively simple example, the item springs back to its original position, and stays there. This is despite the list of items being updated correctly, and even the index provided by the ReorderableColumn being correct.

In the video below, the index is visible in parentheses to the right of the relevant filename. I've also included the live log output below the window, which shows the items in the list are being reordered correctly.

https://github.com/user-attachments/assets/cb9c577d-4bb8-42d3-a434-a99bf901eb56

Thanks for the great library, and I appreciate the help!

gdude2002 avatar Mar 27 '25 15:03 gdude2002

Hmm that's weird, haven't seen this before. Any chance you can share the code? (with all the sensitive/irrelevant stuff removed of course, just need the list part) That would really help me debug.

Calvin-LL avatar Mar 27 '25 16:03 Calvin-LL

Hey, thanks for the response - I linked the code at the top of the issue!

I'm still relatively new to compose so I'm sure it's my fault, I just have no idea where to look haha

gdude2002 avatar Mar 27 '25 16:03 gdude2002

I suspect that this may have something to do with

var files by remember {
    mutableStateOf(directoryWatcher!!.files)
}

Wrapping directoryWatcher!!.files in mutableStateOf may be causing Compose not to recompose after

files.apply {
    add(toIndex, removeAt(fromIndex))
}

.

If you put

LaunchedEffect(list){
    println("List updated: $list")
}

right above the ReorderableColumn, does it get called when the list updates?

Calvin-LL avatar Mar 28 '25 05:03 Calvin-LL

It does get called, yeah. I actually added that files variable due to the note in your README, in the hopes it'd solve this issue. The behaviour was no different before, though.

The directoryWatcher!!.files list is a SnapshotStateList, though coercing it to a standard mutable list and removing the mutableStateOf doesn't change how the reorderable items change, and the LaunchedEffect body is still called.

Apologies for the response delay, I'm not actually back in the office until tomorrow. Thanks for your help so far!

gdude2002 avatar Mar 30 '25 21:03 gdude2002

Switching to a rudimentary approach with up/down buttons in a normal Column doesn't result in the same problem, so I'm not sure that this is a composition issue with my own code.

https://github.com/user-attachments/assets/7aa18918-7acc-499a-a8f1-1b16cc3529d3

gdude2002 avatar Apr 07 '25 08:04 gdude2002