All drag and drop libraries using Reanimated seems to be broken #8181
-
Hello, I tried to recreate a drag and drop system from scratch and it works fine on the web (since there is no UI thread, everything happens sequently), but I too encountered the flickering issue. See for yourself: iOSScreen.Recording.2025-09-01.at.09.25.26.movAndroidScreen.Recording.2025-09-01.at.09.26.55.movHere is the associated gist: It's a basic example as it handles only list with same size items, but I think it's a good starting point, since there is less than 170 lines of code, to find a solution to this flickering. From what I understand, basically it's kind of a race condition between JS and UI thread. When we drop the dragged item, we want to update the state to reflect the new order, except we also need to reset the shared value for the dragged item, but it kind of happens at almost the same time, causing a flickering issue. Any idea how to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hey @Daavidaviid! This is a design difference behind the New Architecture implementation of Reanimated. The problem is that you cannot synchronize SharedValue's update with the React's render because Reanimated's updates from the JS side are batched and pushed as a larger batch of updates instead of being pushed immediately to the native side (which is different from the Old Architecture behavior where all changes were implemented directly on the view without any batching mechanism and waiting for the batched commit of changes). There is no way to solve this with an ease without using any hacks like applying some "correctness" offset that will move the view to the current position doing render or positioning all items absolutely and updating their positions only via Reanimated, not via React's renders. Both are quite tricky and hard to implement on your own. I am using the second approach in my library that I wrote some time ago. If you are interested, you may want to check it out: https://github.com/MatiPl01/react-native-sortables It doesn't support virtualized lists yet, but for simpler sortables, where you don't use hundreds of elements, it should be sufficient and work as expected. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I wasn't able to find (maybe I didn't search enough) how to trigger a callback on drop (to update order information in the api side) EDIT: https://react-native-sortables-docs.vercel.app/grid/props#ondragend |
Beta Was this translation helpful? Give feedback.
Since my library is not implemented on top of the
FlatList
or other list, you can have anything, like header, footer, etc. You can just render all the stuff inside a singleScrollView
like this:Yes, it supports any kind of content change, addition, removal, order change.
But keep in mind, that it renders all items at once without any batching (which is normally performed while using virtualized lists like a
FlatList
), so this library might not be a good solution if you want to render a lot of items for reordering.Here are some examples t…