-
-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with DragOverlay measuring (#427)
* Fix issues with DragOverlay measuring * Simplified measuring strategy for DragOverlay This approach is transform agnostic to keep things simple and reliable. It can be improved later down the road.
- Loading branch information
Showing
12 changed files
with
92 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@dnd-kit/core": major | ||
"@dnd-kit/sortable": major | ||
--- | ||
|
||
- Using transform-agnostic measurements for the DragOverlay node. | ||
- Renamed the `overlayNode` property to `dragOverlay` on the `DndContextDescriptor` interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export {useDerivedTransform} from './useDerivedTransform'; | ||
export {useDropAnimation, DropAnimation} from './useDropAnimation'; | ||
export {useDropAnimation} from './useDropAnimation'; | ||
export type {DropAnimation} from './useDropAnimation'; |
44 changes: 0 additions & 44 deletions
44
packages/core/src/components/DragOverlay/hooks/useDerivedTransform.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/core/src/hooks/utilities/useDragOverlayMeasuring.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {useMemo} from 'react'; | ||
import {useNodeRef} from '@dnd-kit/utilities'; | ||
|
||
import {getMeasurableNode} from '../../utilities/nodes'; | ||
import {getLayoutRect} from '../../utilities/rect'; | ||
import type {DndContextDescriptor} from '../../store'; | ||
import type {ViewRect} from '../../types'; | ||
|
||
import {createUseRectFn} from './useRect'; | ||
|
||
interface Arguments { | ||
disabled: boolean; | ||
forceRecompute: boolean; | ||
} | ||
|
||
// To-do: Delete and replace with `getViewRect` when https://github.com/clauderic/dnd-kit/pull/415 is merged | ||
function getDragOverlayRect(element: HTMLElement): ViewRect { | ||
const {width, height, offsetLeft, offsetTop} = getLayoutRect(element); | ||
|
||
return { | ||
top: offsetTop, | ||
bottom: offsetTop + height, | ||
left: offsetLeft, | ||
right: offsetLeft + width, | ||
width, | ||
height, | ||
offsetTop, | ||
offsetLeft, | ||
}; | ||
} | ||
const useDragOverlayRect = createUseRectFn(getDragOverlayRect); | ||
|
||
export function useDragOverlayMeasuring({ | ||
disabled, | ||
forceRecompute, | ||
}: Arguments): DndContextDescriptor['dragOverlay'] { | ||
const [nodeRef, setRef] = useNodeRef(); | ||
const rect = useDragOverlayRect( | ||
disabled ? null : getMeasurableNode(nodeRef.current), | ||
forceRecompute | ||
); | ||
|
||
return useMemo( | ||
() => ({ | ||
nodeRef, | ||
rect, | ||
setRef, | ||
}), | ||
[rect, nodeRef, setRef] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters