فهرست منبع

Merge pull request #2132 from DouyinFE/fix/transfer-drag

fix: Fixed the issue in Transfer that quick drag failed due to too lo…
代强 1 سال پیش
والد
کامیت
e8e43cbfea
1فایلهای تغییر یافته به همراه17 افزوده شده و 22 حذف شده
  1. 17 22
      packages/semi-ui/_sortable/index.tsx

+ 17 - 22
packages/semi-ui/_sortable/index.tsx

@@ -34,10 +34,6 @@ import type { SortableTransition } from '@dnd-kit/sortable/dist/hooks/types';
 import { isNull } from 'lodash';
 import { isNull } from 'lodash';
 
 
 const defaultPrefix = 'semi-sortable';
 const defaultPrefix = 'semi-sortable';
-const defaultConstraint = {
-    delay: 150,
-    tolerance: 5,
-};
 
 
 interface OnSortEndProps {
 interface OnSortEndProps {
     oldIndex: number;
     oldIndex: number;
@@ -91,13 +87,16 @@ function DefaultContainer(props) {
     return <div style={{ overflow: 'auto' }} {...props}></div>;
     return <div style={{ overflow: 'auto' }} {...props}></div>;
 }
 }
 
 
+const defaultKeyBoardOptions = {
+    coordinateGetter: sortableKeyboardCoordinates,
+};
+
 export function Sortable({
 export function Sortable({
     items,
     items,
     onSortEnd,
     onSortEnd,
     adjustScale,
     adjustScale,
     renderItem,
     renderItem,
     transition,
     transition,
-    activationConstraint = defaultConstraint,
     collisionDetection = closestCenter,
     collisionDetection = closestCenter,
     strategy = rectSortingStrategy,
     strategy = rectSortingStrategy,
     useDragOverlay = true,
     useDragOverlay = true,
@@ -108,15 +107,9 @@ export function Sortable({
 
 
     const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
     const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
     const sensors = useSensors(
     const sensors = useSensors(
-        useSensor(MouseSensor, {
-            activationConstraint, 
-        }),
-        useSensor(TouchSensor, {
-            activationConstraint,
-        }),
-        useSensor(KeyboardSensor, {
-            coordinateGetter: sortableKeyboardCoordinates,
-        })
+        useSensor(MouseSensor),
+        useSensor(TouchSensor),
+        useSensor(KeyboardSensor, defaultKeyBoardOptions)
     );
     );
     const getIndex = useCallback((id: UniqueIdentifier) => items.indexOf(id), [items]);
     const getIndex = useCallback((id: UniqueIdentifier) => items.indexOf(id), [items]);
     const activeIndex = useMemo(() => activeId ? getIndex(activeId) : -1, [getIndex, activeId]);
     const activeIndex = useMemo(() => activeId ? getIndex(activeId) : -1, [getIndex, activeId]);
@@ -235,14 +228,16 @@ export function SortableItem({
         }
         }
     );
     );
 
 
-    const wrapperStyle = (!isNull(animation)) ? {
-        transform: cssDndKit.Transform.toString({
-            ...transform,
-            scaleX: 1,
-            scaleY: 1,
-        }),
-        transition: transition,
-    } : undefined;
+    const wrapperStyle = useMemo(() => {
+        return (!isNull(animation)) ? {
+            transform: cssDndKit.Transform.toString({
+                ...transform,
+                scaleX: 1,
+                scaleY: 1,
+            }),
+            transition: transition,
+        } : undefined;
+    }, [animation, transform, transition]);
 
 
     return <div 
     return <div 
         ref={setNodeRef}
         ref={setNodeRef}