Skip to content

Commit

Permalink
fix: call start drag on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
le-ar committed Jan 24, 2024
1 parent e787ab7 commit f2694a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/components/DragDropContextRootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ export function DragDropContextRootView(props: DragDropContextRootViewProps) {
[startDragMeasureInfo]
);

const onDragEnd = useCallback(() => {
'worklet';
modify(
startDragMeasureInfo,
() => {
'worklet';
return null;
},
true
);
}, [startDragMeasureInfo]);

const value = useMemo<DragDropContextType>(
() => ({ registerDragDropArea, removeDragDropArea, startDrag }),
[registerDragDropArea, removeDragDropArea, startDrag]
Expand All @@ -142,7 +154,8 @@ export function DragDropContextRootView(props: DragDropContextRootViewProps) {
isMoving,
dragDropItemInfo,
hoveredItemMeasurement,
dragDropAreas
dragDropAreas,
onDragEnd
);

return (
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useDragDropMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function useDragDropMove(
isMoving: SharedValue<boolean>,
dragDropItemInfo: SharedValue<DragDropItemInfo | null>,
hoveredItemMeasurement: SharedValue<MeasuredDimensions | null>,
dragDropAreas: SharedValue<DragDropAreas>
dragDropAreas: SharedValue<DragDropAreas>,
onDragEnd: () => void
) {
const { clearHoveredItem, moveHoveredItem, measureHoveredItem } =
useContext(HoveredItemContext);
Expand Down Expand Up @@ -90,6 +91,7 @@ export function useDragDropMove(

stopScroll();
runOnJS(clearHoveredItem)();
onDragEnd();

if (dragDropItemInfo.value != null) {
dragDropItemInfo.value.onEnd?.();
Expand All @@ -102,7 +104,7 @@ export function useDragDropMove(
true
);
}
}, [dragDropItemInfo, clearHoveredItem, stopScroll]);
}, [dragDropItemInfo, clearHoveredItem, stopScroll, onDragEnd]);

const prevIsMoving = useSharedValue(isMoving.value);
useDerivedValue(() => {
Expand Down

0 comments on commit f2694a4

Please sign in to comment.