Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[META] Momentum and currentDelta support for gestures #806

Open
runspired opened this issue Jun 11, 2015 · 5 comments
Open

[META] Momentum and currentDelta support for gestures #806

runspired opened this issue Jun 11, 2015 · 5 comments

Comments

@runspired
Copy link
Contributor

deltaX and deltaY currently represent the distance from the origin event. This is great for simple CSS transforms and the like, but more event context is needed to build gestures with physics.

Example issue/PR #748

I propose hammer should expose something akin to originDeltas and currentDeltas.
I think that any actual momentum calculation is better left to a plugin or individual implementation, but that's up for debate.

@runspired
Copy link
Contributor Author

Related: #728

@runspired
Copy link
Contributor Author

Also related: #730

@runspired
Copy link
Contributor Author

PR #717 has a fix for #718 that helps with sensitivity when detecting swipes.

arschmitz pushed a commit that referenced this issue Aug 8, 2015
if after pinch/rotate, one finger touchends before the other, swipe is
incorrectly triggered because the last gesture is a single-touch
gesture. this checked for maximum pointers in gesture

Fixes #640
Ref #639
Ref #806
Closes #669
@runspired
Copy link
Contributor Author

As with #748, this is going to go in a Minor release as it's not an actual bug and represents an additional behavior.

@linonetwo
Copy link

linonetwo commented Jul 14, 2023

For minimap usage, to fix

deltaX and deltaY currently represent the distance from the origin event.

Currently, you will need to track the current location manually:

  onDragOrPan: function ({ deltaX, deltaY }) {
    if (this.props.onPanTo) {
      // Calculate where event pans to, in editor coordinates
      var x = this.state.panStartPoint[0];
      var y = this.state.panStartPoint[1];
      var panscale = 1 / this.props.viewscale;
      const speedupFactorX = this.props.viewrectangle[2] / this.props.width * 2;
      const speedupFactorY = this.props.viewrectangle[3] / this.props.height * 2;
      x -= deltaX / panscale * speedupFactorX;
      y -= deltaY / panscale * speedupFactorY;
      var panTo = { x: Math.round(x), y: Math.round(y) };
      this.props.onPanTo(panTo, event);
    }
  },
  onTrackStart(event) {
    this.state.panStartPoint[0] = -this.props.viewrectangle[0];
    this.state.panStartPoint[1] = -this.props.viewrectangle[1];
    this._topElement.addEventListener('panmove', this.onTrack);
    this._topElement.addEventListener('panend', this.onTrackEnd);
  },
  onTrack(event) {
    this.onDragOrPan({
      deltaX: event.gesture.deltaX,
      deltaY: event.gesture.deltaY,
    });
  },
  onTrackEnd(event) {
    // Don't click app (unselect)
    event.stopPropagation();
    this._topElement.removeEventListener('panmove', this.onTrack);
    this._topElement.removeEventListener('panend', this.onTrackEnd);
  },
  _setupEvents: function() {
    this.hammer = new Hammer.Manager(this._topElement, {
      domEvents: true,
      inputClass: hammerhacks.Input,
      recognizers: [
        [Hammer.Tap],
        [Hammer.Pan, { direction: Hammer.DIRECTION_ALL, threshold: 5 }],
      ],
    });
    this.hammer.on('tap', (event) => this.props.onTap(event));
    this._topElement.addEventListener('panstart', (event) => this.onTrackStart(event));
  }

note that the

domEvents: true,

make this._topElement.addEventListener('panstart', possible, which is not a native dom event nor a react event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants