Skip to content

fix: Drag callbacks order and state for very short and overlapping drags - #640

Draft
MatiPl01 wants to merge 4 commits into
mainfrom
fix/drag-lifecycle-edge-cases
Draft

MatiPl01 wants to merge 4 commits into
mainfrom
fix/drag-lifecycle-edge-cases

Conversation

@MatiPl01

@MatiPl01 MatiPl01 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Description

Edge cases in the drag state handling for very short and overlapping drags:

  • onDragStart is called after a short delay. When the drag ended before it was delivered (the finger lifted within about two frames of the activation), onDragEnd was called first and onDragStart afterwards with fromIndex: -1. An app that sets a flag in onDragStart and clears it in onDragEnd ended up with the flag stuck. The start callback is now delivered right before the end one in that case, with the order from the drag start.
  • The timeout that finishes a drop marked the active item as dropped and reset the layer even when another item had been picked up, or was still being dropped, in the meantime. Only the last dropped item finishes the drop now. onActiveItemDropped is still called for every item.
  • On web all sortables shared one drag state object (shared values keep the object they are given there), so one sortable could cancel a pending activation of another one.

Testing

Six new jest tests, four fail on main (the first one receives end before start with fromIndex: -1). The other two guard what this change adds: a single onDragStart call for a regular drag, and the drag state not being shared by two sortables. Regular drags checked on the iOS simulator (Fabric).

Evidence
Tests on main before-tests-on-main.txt
Tests with the fix after-tests-with-fix.txt

…ng drags

onDragStart is called after a delay, so a drag that ended before it was delivered called onDragEnd first and onDragStart afterwards with fromIndex -1. The start callback is now delivered before the end one in that case.

The timeout that finishes a drop also marked the active item as dropped and reset the layer when another item had already been picked up.

The drag state object was shared between all sortables on web, where shared values keep the object they are given.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
react-native-sortables-docs Ignored Ignored Preview Nov 26, 2026 1:55pm UTC

@MatiPl01 MatiPl01 self-assigned this Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant