@@ -7,33 +7,27 @@ import { useDraggableSort, type UseDraggableSortOptions } from "./useDraggableSo
77
88export type UseDraggableStackOptions = Pick <
99 UseDraggableSortOptions ,
10- "initialOrder " | "onOrderChange" | "onOrderUpdate" | "shouldSwapWorklet"
10+ "childrenIds " | "onOrderChange" | "onOrderUpdate" | "shouldSwapWorklet"
1111> & {
1212 gap ?: number ;
1313 horizontal ?: boolean ;
1414} ;
1515export const useDraggableStack = ( {
16- initialOrder ,
16+ childrenIds ,
1717 onOrderChange,
1818 onOrderUpdate,
1919 gap = 0 ,
2020 horizontal = false ,
2121 shouldSwapWorklet = doesOverlapOnAxis ,
2222} : UseDraggableStackOptions ) => {
23- const {
24- draggableIds,
25- draggableStates,
26- draggableActiveId,
27- draggableOffsets,
28- draggableRestingOffsets,
29- draggableLayouts,
30- } = useDndContext ( ) ;
23+ const { draggableStates, draggableActiveId, draggableOffsets, draggableRestingOffsets, draggableLayouts } =
24+ useDndContext ( ) ;
3125 const axis = horizontal ? "x" : "y" ;
3226 const size = horizontal ? "width" : "height" ;
3327
3428 const { draggablePlaceholderIndex, draggableSortOrder } = useDraggableSort ( {
3529 horizontal,
36- initialOrder ,
30+ childrenIds ,
3731 onOrderChange,
3832 onOrderUpdate,
3933 shouldSwapWorklet,
@@ -47,7 +41,7 @@ export const useDraggableStack = ({
4741 const { value : sortOrder } = draggableSortOrder ;
4842
4943 const nextIndex = sortOrder . findIndex ( ( itemId ) => itemId === id ) ;
50- const prevIndex = initialOrder . findIndex ( ( itemId ) => itemId === id ) ;
44+ const prevIndex = childrenIds . findIndex ( ( itemId ) => itemId === id ) ;
5145
5246 let offset = 0 ;
5347 // Accumulate the directional offset for the current item accross its siblings in the stack
@@ -62,7 +56,7 @@ export const useDraggableStack = ({
6256 // Can happen if some items are being removed from the stack
6357 continue ;
6458 }
65- const prevSiblingIndex = initialOrder . findIndex ( ( itemId ) => itemId === siblingId ) ;
59+ const prevSiblingIndex = childrenIds . findIndex ( ( itemId ) => itemId === siblingId ) ;
6660 // Accummulate the directional offset for the active item
6761 if ( nextSiblingIndex < nextIndex && prevSiblingIndex > prevIndex ) {
6862 // console.log(
@@ -78,7 +72,7 @@ export const useDraggableStack = ({
7872 }
7973 return offset ;
8074 } ,
81- [ draggableLayouts , draggableSortOrder , gap , horizontal , initialOrder ] ,
75+ [ draggableLayouts , draggableSortOrder , gap , horizontal , childrenIds ] ,
8276 ) ;
8377
8478 const refreshOffsets = useCallback ( ( ) => {
@@ -121,7 +115,7 @@ export const useDraggableStack = ({
121115
122116 // Track items being added or removed from the stack
123117 useAnimatedReaction (
124- ( ) => draggableIds . value ,
118+ ( ) => childrenIds ,
125119 ( next , prev ) => {
126120 // Ignore initial reaction
127121 if ( prev === null ) {
@@ -133,7 +127,7 @@ export const useDraggableStack = ({
133127 // Refresh all offsets
134128 refreshOffsets ( ) ;
135129 } ,
136- [ initialOrder ] ,
130+ [ childrenIds ] ,
137131 ) ;
138132
139133 // Track sort order changes and update the offsets
0 commit comments