|
1 | 1 | import { State } from '../../State';
|
2 | 2 | import { DEFAULT_TOUCH_SLOP } from '../constants';
|
3 |
| -import { AdaptedEvent, Config, StylusData } from '../interfaces'; |
| 3 | +import { AdaptedEvent, Config, StylusData, WheelDevice } from '../interfaces'; |
4 | 4 |
|
5 | 5 | import GestureHandler from './GestureHandler';
|
6 | 6 |
|
@@ -57,6 +57,10 @@ export default class PanGestureHandler extends GestureHandler {
|
57 | 57 | private activateAfterLongPress = 0;
|
58 | 58 | private activationTimeout = 0;
|
59 | 59 |
|
| 60 | + private enableTrackpadTwoFingerGesture = false; |
| 61 | + private endWheelTimeout = 0; |
| 62 | + private wheelDevice = WheelDevice.UNDETERMINED; |
| 63 | + |
60 | 64 | public init(ref: number, propsRef: React.RefObject<unknown>): void {
|
61 | 65 | super.init(ref, propsRef);
|
62 | 66 | }
|
@@ -161,6 +165,11 @@ export default class PanGestureHandler extends GestureHandler {
|
161 | 165 | this.failOffsetYStart = Number.MIN_SAFE_INTEGER;
|
162 | 166 | }
|
163 | 167 | }
|
| 168 | + |
| 169 | + if (this.config.enableTrackpadTwoFingerGesture !== undefined) { |
| 170 | + this.enableTrackpadTwoFingerGesture = |
| 171 | + this.config.enableTrackpadTwoFingerGesture; |
| 172 | + } |
164 | 173 | }
|
165 | 174 |
|
166 | 175 | protected resetConfig(): void {
|
@@ -351,6 +360,65 @@ export default class PanGestureHandler extends GestureHandler {
|
351 | 360 | }
|
352 | 361 | }
|
353 | 362 |
|
| 363 | + private scheduleWheelEnd(event: AdaptedEvent) { |
| 364 | + clearTimeout(this.endWheelTimeout); |
| 365 | + |
| 366 | + this.endWheelTimeout = setTimeout(() => { |
| 367 | + if (this.currentState === State.ACTIVE) { |
| 368 | + this.end(); |
| 369 | + this.tracker.removeFromTracker(event.pointerId); |
| 370 | + this.currentState = State.UNDETERMINED; |
| 371 | + } |
| 372 | + |
| 373 | + this.wheelDevice = WheelDevice.UNDETERMINED; |
| 374 | + }, 30); |
| 375 | + } |
| 376 | + |
| 377 | + protected onWheel(event: AdaptedEvent): void { |
| 378 | + if ( |
| 379 | + this.wheelDevice === WheelDevice.MOUSE || |
| 380 | + !this.enableTrackpadTwoFingerGesture |
| 381 | + ) { |
| 382 | + return; |
| 383 | + } |
| 384 | + |
| 385 | + if (this.currentState === State.UNDETERMINED) { |
| 386 | + this.wheelDevice = |
| 387 | + event.wheelDeltaY! % 120 !== 0 |
| 388 | + ? WheelDevice.TOUCHPAD |
| 389 | + : WheelDevice.MOUSE; |
| 390 | + |
| 391 | + if (this.wheelDevice === WheelDevice.MOUSE) { |
| 392 | + this.scheduleWheelEnd(event); |
| 393 | + return; |
| 394 | + } |
| 395 | + |
| 396 | + this.tracker.addToTracker(event); |
| 397 | + |
| 398 | + const lastCoords = this.tracker.getAbsoluteCoordsAverage(); |
| 399 | + this.lastX = lastCoords.x; |
| 400 | + this.lastY = lastCoords.y; |
| 401 | + |
| 402 | + this.startX = this.lastX; |
| 403 | + this.startY = this.lastY; |
| 404 | + |
| 405 | + this.begin(); |
| 406 | + this.activate(); |
| 407 | + } |
| 408 | + this.tracker.track(event); |
| 409 | + |
| 410 | + const lastCoords = this.tracker.getAbsoluteCoordsAverage(); |
| 411 | + this.lastX = lastCoords.x; |
| 412 | + this.lastY = lastCoords.y; |
| 413 | + |
| 414 | + const velocity = this.tracker.getVelocity(event.pointerId); |
| 415 | + this.velocityX = velocity.x; |
| 416 | + this.velocityY = velocity.y; |
| 417 | + |
| 418 | + this.tryToSendMoveEvent(false, event); |
| 419 | + this.scheduleWheelEnd(event); |
| 420 | + } |
| 421 | + |
354 | 422 | private shouldActivate(): boolean {
|
355 | 423 | const dx: number = this.getTranslationX();
|
356 | 424 |
|
|
0 commit comments