optimize dnd drag code (#3768)

This commit is contained in:
heheer
2025-02-12 15:25:31 +08:00
committed by GitHub
parent 06a8a5e23d
commit 132cf69372
6 changed files with 17 additions and 15 deletions

View File

@@ -16,17 +16,16 @@ type Props<T = any> = {
renderClone?: DraggableChildrenFn;
children: ({
provided,
snapshot,
draggingItemHeight
snapshot
}: {
provided: DroppableProvided;
snapshot: DroppableStateSnapshot;
draggingItemHeight: number;
}) => ReactElement<HTMLElement, string>;
dataList: T[];
zoom?: number;
};
function DndDrag<T>({ children, renderClone, onDragEndCb, dataList }: Props<T>) {
function DndDrag<T>({ children, renderClone, onDragEndCb, dataList, zoom = 1 }: Props<T>) {
const [draggingItemHeight, setDraggingItemHeight] = useState(0);
const onDragStart = (start: DragStart) => {
@@ -53,7 +52,12 @@ function DndDrag<T>({ children, renderClone, onDragEndCb, dataList }: Props<T>)
return (
<DragDropContext onDragStart={onDragStart} onDragEnd={onDragEnd}>
<Droppable droppableId="droppable" renderClone={renderClone}>
{(provided, snapshot) => children({ provided, snapshot, draggingItemHeight })}
{(provided, snapshot) => (
<>
{children({ provided, snapshot })}
{snapshot.isDraggingOver && <Box height={`${draggingItemHeight / zoom}px`} />}
</>
)}
</Droppable>
</DragDropContext>
);