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

Enabling pinch with any number of fingers #390

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controls/Drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ function DragControlMethod(element, pointerType, opts) {
y: new Dynamics()
};

this._hammer = HammerGestures.get(element, pointerType);
this._hammer = HammerGestures.get(element, pointerType, this._opts.hammerEvent);

this._hammer.on("hammer.input", this._handleHammerEvent.bind(this));

if (this._opts.hammerEvent != 'pan' && this._opts.hammerEvent != 'pinch') {
if (this._opts.hammerEvent != 'pan' && this._opts.hammerEvent != 'pinch' && this._opts.hammerEvent != 'multipinch') {
throw new Error(this._opts.hammerEvent + ' is not a hammerEvent managed in DragControlMethod');
}

Expand Down
12 changes: 8 additions & 4 deletions src/controls/HammerGestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ function HammerGestures() {
}


HammerGestures.prototype.get = function(element, type) {
HammerGestures.prototype.get = function(element, type, hammerEvent) {
var key = getKeyForElementAndType(element, type);
if (!this._managers[key]) {
this._managers[key] = this._createManager(element, type);
this._managers[key] = this._createManager(element, type, hammerEvent);
this._refCount[key] = 0;
}
this._refCount[key]++;
return new HammerGesturesHandle(this, this._managers[key], element, type);
};


HammerGestures.prototype._createManager = function(element, type) {
HammerGestures.prototype._createManager = function(element, type, hammerEvent) {
var manager = new Hammer.Manager(element);

// Managers are created with different parameters for different pointer
Expand All @@ -63,7 +63,11 @@ HammerGestures.prototype._createManager = function(element, type) {
// On touch one wants to have both panning and pinching. The panning
// recognizer needs a threshold to allow the pinch to be recognized.
manager.add(new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 20, pointers: 1 }));
manager.add(new Hammer.Pinch());
if (hammerEvent == 'multipinch') {
manager.add(new Hammer.Pinch({event: 'multipinch', pointers: 0, threshold: 0}));
} else {
manager.add(new Hammer.Pinch());
}
}

return manager;
Expand Down
10 changes: 7 additions & 3 deletions src/controls/registerDefaultControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function registerDefaultControls(controls, element, opts) {
eKey: new KeyControlMethod(69, 'roll', -0.7, 3)
};

var enabledControls = ['scrollZoom', 'touchView', 'pinch' ];
var enabledControls = ['scrollZoom', 'touchView', 'pinch', 'rotate' ];

if (opts.scrollZoom !== false) {
controlMethods.scrollZoom = new ScrollZoomControlMethod(element); //{ frictionTime: 0 }
Expand All @@ -82,9 +82,13 @@ function registerDefaultControls(controls, element, opts) {
};


switch (opts.dragMode) {
switch (opts.dragMode) {
case 'multipinch':
controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'multipinch' });
controlMethods.touchView = new DragControlMethod(element, 'touch');
break;
case 'pinch':
controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'pinch' });
controlMethods.pinch = new DragControlMethod(element, 'touch', { hammerEvent: 'pinch' });
break;
case 'pan':
controlMethods.touchView = new DragControlMethod(element, 'touch');
Expand Down