Skip to content

Commit 69ad8a6

Browse files
authored
fix: DragProvider drag end index assignment (#411)
## Description Moves the assignment of fromIndex and toIndex earlier in the drag end handler to fix incorrect fromIndex value. Previously, fromIndex was always -1 when using the onDragEnd callback because the state was being reset too early. This change ensures that the correct indices are captured before any cleanup happens.
1 parent 56f0ef3 commit 69ad8a6

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

packages/react-native-sortables/src/providers/shared/DragProvider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ const { DragProvider, useDragContext } = createProvider('Drag')<
457457
}
458458

459459
clearAnimatedTimeout(activationTimeoutId.value);
460+
461+
const fromIndex = dragStartIndex.value;
462+
const toIndex = keyToIndex.value[key]!;
463+
460464
touchStartTouch.value = null;
461465
currentTouch.value = null;
462466
activationState.value = DragActivationState.INACTIVE;
@@ -489,9 +493,6 @@ const { DragProvider, useDragContext } = createProvider('Drag')<
489493
updateLayer?.(LayerState.INTERMEDIATE);
490494
haptics.medium();
491495

492-
const fromIndex = dragStartIndex.value;
493-
const toIndex = keyToIndex.value[key]!;
494-
495496
stableOnDragEnd({
496497
fromIndex,
497498
indexToKey: indexToKey.value,

0 commit comments

Comments
 (0)