Skip to content

feat: Add reorderOnDrag prop to delay sorting until the item is dropped#577

Closed
MatiPl01 wants to merge 1 commit into
mainfrom
feat/reorder-on-drag
Closed

feat: Add reorderOnDrag prop to delay sorting until the item is dropped#577
MatiPl01 wants to merge 1 commit into
mainfrom
feat/reorder-on-drag

Conversation

@MatiPl01

Copy link
Copy Markdown
Owner

Description

Adds a reorderOnDrag prop (default true). With reorderOnDrag={false} items don't reorder while dragging; the new order is applied only when the active item is dropped. Builds on #525 and fixes the drag-end callback ordering.

The prospective order is now computed during the drag and committed in handleDragEnd before onDragEnd / onActiveItemDropped fire, so those callbacks (and the grid data param) report the final order. In #525 the reorder was applied by a deferred reaction that ran after onDragEnd, so a controlled list updating from params.data on drop persisted the pre-drop order.

Changes showcase

reorderOnDrag={false} with controlled data (onDragEnd={p => setData(p.data)}), dragging Item 1 across the grid:

Before (#525) After
drag before.gif here drag after.gif here

Before, the dropped item lands in the wrong place because onDragEnd reports the pre-reorder order (from 0 to 0). After, it lands exactly where dropped (from 0 to 7) and the controlled order sticks.

Key change
// useOrderUpdater: compute the order during the drag, but stash it instead of applying
if (reorderOnDrag) {
  handleOrderChange(activeKey, activeIndex, newOrder.indexOf(activeKey), newOrder);
} else {
  pendingDropOrder.value = newOrder;
}

// DragProvider.handleDragEnd: commit it before the drag-end callbacks run
const newOrder = pendingDropOrder.value;
if (newOrder) {
  pendingDropOrder.value = null;
  indexToKey.value = newOrder;
  dropKeyToIndex = getKeyToIndex(newOrder);
  // fire onOrderChange(...), then onDragEnd / onActiveItemDropped with the final order
}

Verified on iOS (Fabric) for Sortable.Grid and Sortable.Flex, with reorderOnDrag both true (items reorder during the drag, unchanged) and false. Docs for the prop, a test, and the drop indicator preview in this mode are still TODO.

When reorderOnDrag is false, items don't reorder during the drag. The prospective order is computed while dragging and committed in handleDragEnd before onDragEnd/onActiveItemDropped fire, so the drag-end callbacks report the final order instead of the pre-drop one.
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
react-native-sortables-docs Ignored Ignored Jun 27, 2026 9:01pm

@MatiPl01 MatiPl01 self-assigned this Jun 27, 2026
@MatiPl01

Copy link
Copy Markdown
Owner Author

Closing this. After building and testing it, delaying the reorder until drop means there's no preview of where the active item will land while dragging, which makes the interaction feel worse than the default live reordering. The default behavior already covers these cases well, so this isn't a good fit to add and isn't needed.

@MatiPl01 MatiPl01 closed this Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant