File tree 3 files changed +19
-1
lines changed
DraggableComponent/collision/dynamic
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import { ComponentDndData } from "../DraggableComponent";
26
26
import { isElement } from "@dnd-kit/dom/utilities" ;
27
27
28
28
import { PointerSensor } from "./PointerSensor" ;
29
+ import { collisionStore } from "../DraggableComponent/collision/dynamic/store" ;
29
30
30
31
const DEBUG = false ;
31
32
@@ -95,6 +96,13 @@ const DragDropContextClient = ({
95
96
96
97
useZoneStore . setState ( { zoneDepthIndex, areaDepthIndex } ) ;
97
98
99
+ // Disable fallback collisions temporarily after zone change, as
100
+ // these can cause unexpected collisions
101
+ collisionStore . setState ( { fallbackEnabled : false } ) ;
102
+ setTimeout ( ( ) => {
103
+ collisionStore . setState ( { fallbackEnabled : true } ) ;
104
+ } , 500 ) ;
105
+
98
106
setTimeout ( ( ) => {
99
107
// Force update after debounce
100
108
manager . collisionObserver . forceUpdate ( true ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { trackMovementInterval } from "./track-movement-interval";
12
12
import { collisionDebug } from "../collision-debug" ;
13
13
import { closestCorners } from "@dnd-kit/collision" ;
14
14
import { DragAxis , Direction } from "../../../../types" ;
15
+ import { collisionStore } from "./store" ;
15
16
16
17
export type CollisionMap = Record <
17
18
string ,
@@ -59,6 +60,8 @@ export const createDynamicCollisionDetector = (
59
60
60
61
const { center : dragCenter } = dragShape ;
61
62
63
+ const { fallbackEnabled } = collisionStore . getState ( ) ;
64
+
62
65
const interval = trackMovementInterval ( position . current , dragAxis ) ;
63
66
64
67
dragOperation . data = {
@@ -128,7 +131,7 @@ export const createDynamicCollisionDetector = (
128
131
return { ...collision , id : shouldFlushId ? "flush" : collision . id } ;
129
132
}
130
133
131
- if ( dragOperation . source ?. id !== droppable . id ) {
134
+ if ( fallbackEnabled && dragOperation . source ?. id !== droppable . id ) {
132
135
// Only calculate fallbacks when the draggable sits within the droppable's axis projection
133
136
const xAxisIntersection =
134
137
dropShape . boundingRectangle . right > dragShape . boundingRectangle . left &&
Original file line number Diff line number Diff line change
1
+ import { createStore } from "zustand/vanilla" ;
2
+
3
+ export const collisionStore = createStore < {
4
+ fallbackEnabled : boolean ;
5
+ } > ( ( ) => ( {
6
+ fallbackEnabled : false ,
7
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments