@@ -83,7 +83,7 @@ export class DragDropRegistry<I, C> implements OnDestroy {
83
83
this . _ngZone . runOutsideAngular ( ( ) => {
84
84
// The event handler has to be explicitly active,
85
85
// because newer browsers make it passive by default.
86
- this . _document . addEventListener ( 'touchmove' , this . _preventDefaultWhileDragging ,
86
+ this . _document . addEventListener ( 'touchmove' , this . _persistentTouchmoveListener ,
87
87
activeCapturingEventOptions ) ;
88
88
} ) ;
89
89
}
@@ -100,7 +100,7 @@ export class DragDropRegistry<I, C> implements OnDestroy {
100
100
this . stopDragging ( drag ) ;
101
101
102
102
if ( this . _dragInstances . size === 0 ) {
103
- this . _document . removeEventListener ( 'touchmove' , this . _preventDefaultWhileDragging ,
103
+ this . _document . removeEventListener ( 'touchmove' , this . _persistentTouchmoveListener ,
104
104
activeCapturingEventOptions ) ;
105
105
}
106
106
}
@@ -120,18 +120,12 @@ export class DragDropRegistry<I, C> implements OnDestroy {
120
120
121
121
if ( this . _activeDragInstances . size === 1 ) {
122
122
const isTouchEvent = event . type . startsWith ( 'touch' ) ;
123
- const moveEvent = isTouchEvent ? 'touchmove' : 'mousemove' ;
124
- const upEvent = isTouchEvent ? 'touchend' : 'mouseup' ;
125
123
126
124
// We explicitly bind __active__ listeners here, because newer browsers will default to
127
125
// passive ones for `mousemove` and `touchmove`. The events need to be active, because we
128
126
// use `preventDefault` to prevent the page from scrolling while the user is dragging.
129
127
this . _globalListeners
130
- . set ( moveEvent , {
131
- handler : ( e : Event ) => this . pointerMove . next ( e as TouchEvent | MouseEvent ) ,
132
- options : activeCapturingEventOptions
133
- } )
134
- . set ( upEvent , {
128
+ . set ( isTouchEvent ? 'touchend' : 'mouseup' , {
135
129
handler : ( e : Event ) => this . pointerUp . next ( e as TouchEvent | MouseEvent ) ,
136
130
options : true
137
131
} )
@@ -150,6 +144,15 @@ export class DragDropRegistry<I, C> implements OnDestroy {
150
144
options : activeCapturingEventOptions
151
145
} ) ;
152
146
147
+ // We don't have to bind a move event for touch drag sequences, because
148
+ // we already have a persistent global one bound from `registerDragItem`.
149
+ if ( ! isTouchEvent ) {
150
+ this . _globalListeners . set ( 'mousemove' , {
151
+ handler : ( e : Event ) => this . pointerMove . next ( e as MouseEvent ) ,
152
+ options : activeCapturingEventOptions
153
+ } ) ;
154
+ }
155
+
153
156
this . _ngZone . runOutsideAngular ( ( ) => {
154
157
this . _globalListeners . forEach ( ( config , name ) => {
155
158
this . _document . addEventListener ( name , config . handler , config . options ) ;
@@ -190,6 +193,14 @@ export class DragDropRegistry<I, C> implements OnDestroy {
190
193
}
191
194
}
192
195
196
+ /** Event listener for `touchmove` that is bound even if no dragging is happening. */
197
+ private _persistentTouchmoveListener = ( event : TouchEvent ) => {
198
+ if ( this . _activeDragInstances . size ) {
199
+ event . preventDefault ( ) ;
200
+ this . pointerMove . next ( event ) ;
201
+ }
202
+ }
203
+
193
204
/** Clears out the global event listeners from the `document`. */
194
205
private _clearGlobalListeners ( ) {
195
206
this . _globalListeners . forEach ( ( config , name ) => {
0 commit comments