@@ -365,13 +365,33 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
365
365
}
366
366
} ;
367
367
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
+
368
379
handleSortMove = e => {
369
380
const { onSortMove} = this . props ;
370
381
e . preventDefault ( ) ; // Prevent scrolling on mobile
371
382
383
+ if ( this . sortMoveAF ) {
384
+ return ;
385
+ }
386
+
372
387
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
+ }
375
395
376
396
if ( onSortMove ) onSortMove ( e ) ;
377
397
} ;
@@ -380,6 +400,12 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
380
400
const { hideSortableGhost, onSortEnd} = this . props ;
381
401
const { collection} = this . manager . active ;
382
402
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
+
383
409
// Remove the event listeners if the node is still in the DOM
384
410
if ( this . listenerNode ) {
385
411
events . move . forEach ( eventName =>
0 commit comments