Ver Fonte

fix: 调整到正确的 history mode

chuancey há 7 anos atrás
pai
commit
2b3accfee4
2 ficheiros alterados com 17 adições e 15 exclusões
  1. 1 0
      src/HistoryLayout/index.tsx
  2. 16 15
      src/lib/dragact.tsx

+ 1 - 0
src/HistoryLayout/index.tsx

@@ -84,6 +84,7 @@ export class HistoryDemo extends React.Component<{}, {}> {
                         {...dragactInit}
                         placeholder={true}
                         ref={n => this.drag = n}
+                        history={true}
                         style={{
                             background: '#003A8C'
                         }}

+ 16 - 15
src/lib/dragact.tsx

@@ -120,8 +120,8 @@ export interface GridItemProvided {
 export class Dragact extends React.Component<DragactProps, DragactState> {
     mapLayoutHistory : string[] = []
     cacheLayouts: string;
-
     activeItem: GridItemEvent
+    
     constructor(props: DragactProps) {
         super(props)
         this.onDrag = this.onDrag.bind(this)
@@ -163,31 +163,26 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
     }
 
     resetLayout = () => {
-       const { compacted, mapLayout } = this.recalculateLayout(this.props.layout)
-       this.cachingLayout();
-       this.storeLayoutToHistory();
-       this.setState({
-           layout: compacted,
-           mapLayout
-       })
+       
+        const { compacted, mapLayout } = this.recalculateLayout(this.props.layout)
+        this.cachingLayout();
+        this.storeLayoutToHistory();
+        this.setState({
+            layout: compacted,
+            mapLayout
+        })
     }
 
     get isHistoryMode () {
-        return !!this.props.history == false
+        return !!this.props.history;
     }
 
     cacheCurrentLayoutStart = (layoutItem: GridItemEvent) => {
-        if(!this.isHistoryMode) {
-            return;
-        }
         this.activeItem = layoutItem
         this.cachingLayout();
     }
 
     cacheCurrentLayoutEnd = (layoutItem: GridItemEvent) => {
-        if (!this.isHistoryMode) {
-            return;
-        }
         const { GridY, GridX, h, w } = this.activeItem;
         if (GridX === layoutItem.GridX && GridY === layoutItem.GridY && h === layoutItem.h && w === layoutItem.w) {
             return;
@@ -196,6 +191,9 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
     }
 
     cachingLayout = () => {
+        if(!this.isHistoryMode) {
+            return;
+        }
         const { mapLayout, layout } = this.state
         this.cacheLayouts = JSON.stringify({
             mapLayout,
@@ -204,6 +202,9 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
     }
 
     storeLayoutToHistory = () => {
+        if(!this.isHistoryMode) {
+            return;
+        }
         this.mapLayoutHistory.push(this.cacheLayouts);
     }