-
-
Notifications
You must be signed in to change notification settings - Fork 639
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
- Loading branch information
Clauderic Demers
committed
Aug 18, 2021
1 parent
59ef705
commit de29ae1
Showing
10 changed files
with
75 additions
and
74 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
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,3 @@ | ||
export {useDerivedTransform} from './useDerivedTransform'; | ||
export {useDropAnimation, DropAnimation} from './useDropAnimation'; | ||
export {useDropAnimation} from './useDropAnimation'; | ||
export type {DropAnimation} from './useDropAnimation'; | ||
export {useDragOverlayMeasuring} from './useDragOverlayMeasuring'; |
44 changes: 0 additions & 44 deletions
44
packages/core/src/components/DragOverlay/hooks/useDerivedTransform.ts
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
packages/core/src/components/DragOverlay/hooks/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,47 @@ | ||
import {useMemo, useRef} from 'react'; | ||
import {Transform, useNodeRef} from '@dnd-kit/utilities'; | ||
|
||
import type {DndContextDescriptor} from '../../../store'; | ||
import type {ClientRect} from '../../../types'; | ||
import {useClientRect} from '../../../hooks/utilities'; | ||
import {getMeasurableNode} from '../../../utilities/nodes'; | ||
|
||
interface Arguments { | ||
disabled: boolean; | ||
forceRecompute: boolean; | ||
} | ||
|
||
export function useDragOverlayMeasuring({ | ||
disabled, | ||
forceRecompute, | ||
}: Arguments): DndContextDescriptor['overlayNode'] { | ||
const transform = useRef<Transform | null>(null); | ||
const [nodeRef, setRef] = useNodeRef(); | ||
const measuredOverlayRect = useClientRect( | ||
disabled ? null : getMeasurableNode(nodeRef.current), | ||
forceRecompute | ||
); | ||
|
||
const rect = useMemo(() => { | ||
return measuredOverlayRect && transform.current | ||
? add(measuredOverlayRect, transform.current) | ||
: null; | ||
}, [measuredOverlayRect]); | ||
|
||
return { | ||
nodeRef, | ||
rect, | ||
setRef, | ||
transform, | ||
}; | ||
} | ||
|
||
function add(rect: ClientRect, transform: Transform) { | ||
return { | ||
...rect, | ||
left: Math.round(rect.left - transform.x), | ||
right: Math.round(rect.right - transform.x), | ||
top: Math.round(rect.top - transform.y), | ||
bottom: Math.round(rect.bottom - transform.y), | ||
}; | ||
} |
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,3 +1,4 @@ | ||
export {DragOverlay, defaultDropAnimation} from './DragOverlay'; | ||
export type {Props} from './DragOverlay'; | ||
export {useDragOverlayMeasuring} from './hooks'; | ||
export type {DropAnimation} from './hooks'; |
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