@@ -109,18 +109,20 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
109
109
* snapshots will serialize window, causing a RangeError
110
110
* https://github.com/clauderic/react-sortable-hoc/issues/249
111
111
*/
112
- const contentWindow = this . props . contentWindow || window ;
113
112
114
113
this . container = typeof getContainer === 'function'
115
114
? getContainer ( this . getWrappedInstance ( ) )
116
115
: findDOMNode ( this ) ;
117
116
this . document = this . container . ownerDocument || document ;
118
- this . scrollContainer = useWindowAsScrollContainer
119
- ? this . document . body
120
- : this . container ;
117
+
118
+ const contentWindow = this . props . contentWindow || this . document . defaultView || window ;
119
+
121
120
this . contentWindow = typeof contentWindow === 'function'
122
121
? contentWindow ( )
123
122
: contentWindow ;
123
+ this . scrollContainer = useWindowAsScrollContainer
124
+ ? this . document . scrollingElement || this . document . documentElement
125
+ : this . container ;
124
126
125
127
for ( const key in this . events ) {
126
128
if ( this . events . hasOwnProperty ( key ) ) {
@@ -273,8 +275,8 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
273
275
this . offsetEdge = this . getEdgeOffset ( node ) ;
274
276
this . initialOffset = this . getOffset ( e ) ;
275
277
this . initialScroll = {
276
- top : this . scrollContainer . scrollTop ,
277
- left : this . scrollContainer . scrollLeft ,
278
+ top : this . container . scrollTop ,
279
+ left : this . container . scrollLeft ,
278
280
} ;
279
281
280
282
this . initialWindowScroll = {
@@ -453,10 +455,22 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
453
455
}
454
456
455
457
getOffset ( e ) {
456
- return {
457
- x : e . touches ? e . touches [ 0 ] . pageX : e . pageX ,
458
- y : e . touches ? e . touches [ 0 ] . pageY : e . pageY ,
459
- } ;
458
+ if ( e . touches && e . touches . length ) {
459
+ return {
460
+ x : e . touches [ 0 ] . pageX ,
461
+ y : e . touches [ 0 ] . pageY ,
462
+ } ;
463
+ } else if ( e . changedTouches && e . changedTouches . length ) {
464
+ return {
465
+ x : e . changedTouches [ 0 ] . pageX ,
466
+ y : e . changedTouches [ 0 ] . pageY ,
467
+ } ;
468
+ } else {
469
+ return {
470
+ x : e . pageX ,
471
+ y : e . pageY ,
472
+ } ;
473
+ }
460
474
}
461
475
462
476
getLockPixelOffsets ( ) {
@@ -568,15 +582,15 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
568
582
animateNodes ( ) {
569
583
const { transitionDuration, hideSortableGhost, onSortOver} = this . props ;
570
584
const nodes = this . manager . getOrderedRefs ( ) ;
571
- const deltaScroll = {
572
- left : this . scrollContainer . scrollLeft - this . initialScroll . left ,
573
- top : this . scrollContainer . scrollTop - this . initialScroll . top ,
585
+ const containerScrollDelta = {
586
+ left : this . container . scrollLeft - this . initialScroll . left ,
587
+ top : this . container . scrollTop - this . initialScroll . top ,
574
588
} ;
575
589
const sortingOffset = {
576
- left : this . offsetEdge . left + this . translate . x + deltaScroll . left ,
577
- top : this . offsetEdge . top + this . translate . y + deltaScroll . top ,
590
+ left : this . offsetEdge . left + this . translate . x + containerScrollDelta . left ,
591
+ top : this . offsetEdge . top + this . translate . y + containerScrollDelta . top ,
578
592
} ;
579
- const scrollDifference = {
593
+ const windowScrollDelta = {
580
594
top : ( window . pageYOffset - this . initialWindowScroll . top ) ,
581
595
left : ( window . pageXOffset - this . initialWindowScroll . left ) ,
582
596
} ;
@@ -641,9 +655,9 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
641
655
if (
642
656
index < this . index &&
643
657
(
644
- ( ( sortingOffset . left + scrollDifference . left ) - offset . width <= edgeOffset . left &&
645
- ( sortingOffset . top + scrollDifference . top ) <= edgeOffset . top + offset . height ) ||
646
- ( sortingOffset . top + scrollDifference . top ) + offset . height <= edgeOffset . top
658
+ ( ( sortingOffset . left + windowScrollDelta . left ) - offset . width <= edgeOffset . left &&
659
+ ( sortingOffset . top + windowScrollDelta . top ) <= edgeOffset . top + offset . height ) ||
660
+ ( sortingOffset . top + windowScrollDelta . top ) + offset . height <= edgeOffset . top
647
661
)
648
662
) {
649
663
// If the current node is to the left on the same row, or above the node that's being dragged
@@ -665,9 +679,9 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
665
679
} else if (
666
680
index > this . index &&
667
681
(
668
- ( ( sortingOffset . left + scrollDifference . left ) + offset . width >= edgeOffset . left &&
669
- ( sortingOffset . top + scrollDifference . top ) + offset . height >= edgeOffset . top ) ||
670
- ( sortingOffset . top + scrollDifference . top ) + offset . height >= edgeOffset . top + height
682
+ ( ( sortingOffset . left + windowScrollDelta . left ) + offset . width >= edgeOffset . left &&
683
+ ( sortingOffset . top + windowScrollDelta . top ) + offset . height >= edgeOffset . top ) ||
684
+ ( sortingOffset . top + windowScrollDelta . top ) + offset . height >= edgeOffset . top + height
671
685
)
672
686
) {
673
687
// If the current node is to the right on the same row, or below the node that's being dragged
@@ -688,13 +702,13 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
688
702
} else {
689
703
if (
690
704
index > this . index &&
691
- ( sortingOffset . left + scrollDifference . left ) + offset . width >= edgeOffset . left
705
+ ( sortingOffset . left + windowScrollDelta . left ) + offset . width >= edgeOffset . left
692
706
) {
693
707
translate . x = - ( this . width + this . marginOffset . x ) ;
694
708
this . newIndex = index ;
695
709
} else if (
696
710
index < this . index &&
697
- ( sortingOffset . left + scrollDifference . left ) <= edgeOffset . left + offset . width
711
+ ( sortingOffset . left + windowScrollDelta . left ) <= edgeOffset . left + offset . width
698
712
) {
699
713
translate . x = this . width + this . marginOffset . x ;
700
714
if ( this . newIndex == null ) {
@@ -705,13 +719,13 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
705
719
} else if ( this . axis . y ) {
706
720
if (
707
721
index > this . index &&
708
- ( sortingOffset . top + scrollDifference . top ) + offset . height >= edgeOffset . top
722
+ ( sortingOffset . top + windowScrollDelta . top ) + offset . height >= edgeOffset . top
709
723
) {
710
724
translate . y = - ( this . height + this . marginOffset . y ) ;
711
725
this . newIndex = index ;
712
726
} else if (
713
727
index < this . index &&
714
- ( sortingOffset . top + scrollDifference . top ) <= edgeOffset . top + offset . height
728
+ ( sortingOffset . top + windowScrollDelta . top ) <= edgeOffset . top + offset . height
715
729
) {
716
730
translate . y = this . height + this . marginOffset . y ;
717
731
if ( this . newIndex == null ) {
0 commit comments