Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
HighCoordination committed Mar 29, 2018
2 parents e97bb54 + dba7137 commit 17d44b1
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/SortableContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,33 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
}
};

_handleSortMove = (e) => {
this.animateNodes();
this.autoscroll();

if (window.requestAnimationFrame)
this.sortMoveAF = null;
else setTimeout(() =>{
this.sortMoveAF = null;
}, 1000/60); // aim for 60 fps
};

handleSortMove = e => {
const {onSortMove} = this.props;
e.preventDefault(); // Prevent scrolling on mobile

if (this.sortMoveAF) {
return;
}

this.updatePosition(e);
this.animateNodes();
this.autoscroll();

if (window.requestAnimationFrame) {
this.sortMoveAF = window.requestAnimationFrame(this._handleSortMove);
} else {
this.sortMoveAF = true;
this._handleSortMove(); // call inner function now if no animation frame
}

if (onSortMove) onSortMove(e);
};
Expand All @@ -387,6 +407,12 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
const {hideSortableGhost, onSortEnd} = this.props;
const {collection} = this.manager.active;

// Remove the move handler if there's a frame that hasn't run yet.
if (window.cancelAnimationFrame && this.sortMoveAF){
window.cancelAnimationFrame(this.sortMoveAF);
this.sortMoveAF = null;
}

// Remove the event listeners if the node is still in the DOM
if (this.listenerNode) {
events.move.forEach(eventName =>
Expand Down

0 comments on commit 17d44b1

Please sign in to comment.