Skip to content

Commit 8b1acf8

Browse files
committed
Improve performance drastically in for Edge & MSIE.
1 parent 5cab628 commit 8b1acf8

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/SortableContainer/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,33 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
365365
}
366366
};
367367

368+
_handleSortMove = (e) => {
369+
this.animateNodes();
370+
this.autoscroll();
371+
372+
if (window.requestAnimationFrame)
373+
this.sortMoveAF = null;
374+
else setTimeout(() =>{
375+
this.sortMoveAF = null;
376+
}, 1000/60); // aim for 60 fps
377+
};
378+
368379
handleSortMove = e => {
369380
const {onSortMove} = this.props;
370381
e.preventDefault(); // Prevent scrolling on mobile
371382

383+
if (this.sortMoveAF) {
384+
return;
385+
}
386+
372387
this.updatePosition(e);
373-
this.animateNodes();
374-
this.autoscroll();
388+
389+
if (window.requestAnimationFrame) {
390+
this.sortMoveAF = window.requestAnimationFrame(this._handleSortMove);
391+
} else {
392+
this.sortMoveAF = true;
393+
this._handleSortMove(); // call inner function now if no animation frame
394+
}
375395

376396
if (onSortMove) onSortMove(e);
377397
};
@@ -380,6 +400,12 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
380400
const {hideSortableGhost, onSortEnd} = this.props;
381401
const {collection} = this.manager.active;
382402

403+
// Remove the move handler if there's a frame that hasn't run yet.
404+
if (window.cancelAnimationFrame && this.sortMoveAF){
405+
window.cancelAnimationFrame(this.sortMoveAF);
406+
this.sortMoveAF = null;
407+
}
408+
383409
// Remove the event listeners if the node is still in the DOM
384410
if (this.listenerNode) {
385411
events.move.forEach(eventName =>

0 commit comments

Comments
 (0)