From be1ed3bcd81e5d63f2fed87bd541e229dc10d909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=90=8D=E9=A1=BA?= <14646433490@qq.com> Date: Sun, 31 Jul 2022 11:53:54 +0800 Subject: [PATCH] fix:Fix sortableContainer distance inaccurate --- src/SortableContainer/index.js | 3 ++- src/utils.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SortableContainer/index.js b/src/SortableContainer/index.js index 9b24a0456..10903f1a7 100644 --- a/src/SortableContainer/index.js +++ b/src/SortableContainer/index.js @@ -15,6 +15,7 @@ import { getElementMargin, getLockPixelOffsets, getPosition, + getLinearDistance, isTouchEvent, limit, NodeType, @@ -191,7 +192,7 @@ export default function sortableContainer( x: this.position.x - position.x, y: this.position.y - position.y, }; - const combinedDelta = Math.abs(delta.x) + Math.abs(delta.y); + const combinedDelta = getLinearDistance(Math.abs(delta.x), Math.abs(delta.y)); this.delta = delta; diff --git a/src/utils.js b/src/utils.js index b62704ea4..e2a21d372 100644 --- a/src/utils.js +++ b/src/utils.js @@ -272,6 +272,10 @@ export function getContainerGridGap(element) { return {x: 0, y: 0}; } +export function getLinearDistance(deltaX, deltaY) { + return Math.sqrt(deltaX ** 2, deltaY ** 2); +} + export const KEYCODE = { TAB: 9, ESC: 27,