framer / motion

Open source, production-ready animation and gesture library for React
https://framer.com/motion
MIT License
22.27k stars 733 forks source link

[FEATURE] Expose moved item index in Reorder.group #2603

Open thecrowkeep opened 1 month ago

thecrowkeep commented 1 month ago

Is your feature request related to a problem? Please describe. Using a Redis DB where items are ordered in a list, to move an item you need to:

  1. Delete the item in the list that is to be moved
  2. Insert the item before or after the position in the list you want it to be in

This is much more performant than rewriting an array every single time a position changes.

However because onReorder only exposes the new state, you have to do a bunch of unnecessary computation to find the difference in the two arrays. It's also awkward to implement, especially considering how simple it would be to use a moved item index and find where in the new array its new index is.

Describe the solution you'd like Either onReorder implements (newItems: any[], movedItem: number) => void or a new method is implemented (movedItem: number, {before: number} | {after: number}) or really any other method that at the very least exposes the moved item index.

Describe alternatives you've considered