@@ -218,6 +218,20 @@ export default class PanGestureHandler extends GestureHandler {
218
218
clearTimeout ( this . activationTimeout ) ;
219
219
}
220
220
221
+ private updateLastCoords ( ) {
222
+ const { x, y } = this . tracker . getAbsoluteCoordsAverage ( ) ;
223
+
224
+ this . lastX = x ;
225
+ this . lastY = y ;
226
+ }
227
+
228
+ private updateVelocity ( pointerId : number ) {
229
+ const { x, y } = this . tracker . getVelocity ( pointerId ) ;
230
+
231
+ this . velocityX = x ;
232
+ this . velocityY = y ;
233
+ }
234
+
221
235
// Events Handling
222
236
protected onPointerDown ( event : AdaptedEvent ) : void {
223
237
if ( ! this . isButtonInConfig ( event . button ) ) {
@@ -229,9 +243,7 @@ export default class PanGestureHandler extends GestureHandler {
229
243
230
244
super . onPointerDown ( event ) ;
231
245
232
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
233
- this . lastX = lastCoords . x ;
234
- this . lastY = lastCoords . y ;
246
+ this . updateLastCoords ( ) ;
235
247
236
248
this . startX = this . lastX ;
237
249
this . startY = this . lastY ;
@@ -250,9 +262,7 @@ export default class PanGestureHandler extends GestureHandler {
250
262
this . offsetX += this . lastX - this . startX ;
251
263
this . offsetY += this . lastY - this . startY ;
252
264
253
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
254
- this . lastX = lastCoords . x ;
255
- this . lastY = lastCoords . y ;
265
+ this . updateLastCoords ( ) ;
256
266
257
267
this . startX = this . lastX ;
258
268
this . startY = this . lastY ;
@@ -299,9 +309,7 @@ export default class PanGestureHandler extends GestureHandler {
299
309
this . offsetX += this . lastX - this . startX ;
300
310
this . offsetY += this . lastY - this . startY ;
301
311
302
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
303
- this . lastX = lastCoords . x ;
304
- this . lastY = lastCoords . y ;
312
+ this . updateLastCoords ( ) ;
305
313
306
314
this . startX = this . lastX ;
307
315
this . startY = this . lastY ;
@@ -320,13 +328,8 @@ export default class PanGestureHandler extends GestureHandler {
320
328
this . tracker . track ( event ) ;
321
329
this . stylusData = event . stylusData ;
322
330
323
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
324
- this . lastX = lastCoords . x ;
325
- this . lastY = lastCoords . y ;
326
-
327
- const velocity = this . tracker . getVelocity ( event . pointerId ) ;
328
- this . velocityX = velocity . x ;
329
- this . velocityY = velocity . y ;
331
+ this . updateLastCoords ( ) ;
332
+ this . updateVelocity ( event . pointerId ) ;
330
333
331
334
this . checkBegan ( ) ;
332
335
@@ -341,13 +344,8 @@ export default class PanGestureHandler extends GestureHandler {
341
344
this . tracker . track ( event ) ;
342
345
this . stylusData = event . stylusData ;
343
346
344
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
345
- this . lastX = lastCoords . x ;
346
- this . lastY = lastCoords . y ;
347
-
348
- const velocity = this . tracker . getVelocity ( event . pointerId ) ;
349
- this . velocityX = velocity . x ;
350
- this . velocityY = velocity . y ;
347
+ this . updateLastCoords ( ) ;
348
+ this . updateVelocity ( event . pointerId ) ;
351
349
352
350
this . checkBegan ( ) ;
353
351
@@ -391,9 +389,7 @@ export default class PanGestureHandler extends GestureHandler {
391
389
392
390
this . tracker . addToTracker ( event ) ;
393
391
394
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
395
- this . lastX = lastCoords . x ;
396
- this . lastY = lastCoords . y ;
392
+ this . updateLastCoords ( ) ;
397
393
398
394
this . startX = this . lastX ;
399
395
this . startY = this . lastY ;
@@ -403,13 +399,8 @@ export default class PanGestureHandler extends GestureHandler {
403
399
}
404
400
this . tracker . track ( event ) ;
405
401
406
- const lastCoords = this . tracker . getAbsoluteCoordsAverage ( ) ;
407
- this . lastX = lastCoords . x ;
408
- this . lastY = lastCoords . y ;
409
-
410
- const velocity = this . tracker . getVelocity ( event . pointerId ) ;
411
- this . velocityX = velocity . x ;
412
- this . velocityY = velocity . y ;
402
+ this . updateLastCoords ( ) ;
403
+ this . updateVelocity ( event . pointerId ) ;
413
404
414
405
this . tryToSendMoveEvent ( false , event ) ;
415
406
this . scheduleWheelEnd ( event ) ;
@@ -540,9 +531,7 @@ export default class PanGestureHandler extends GestureHandler {
540
531
} , this . activateAfterLongPress ) ;
541
532
}
542
533
} else {
543
- const velocity = this . tracker . getVelocity ( event . pointerId ) ;
544
- this . velocityX = velocity . x ;
545
- this . velocityY = velocity . y ;
534
+ this . updateVelocity ( event . pointerId ) ;
546
535
}
547
536
}
548
537
0 commit comments