Skip to content

Commit 7f4f106

Browse files
committed
Merge pull request #24 from nmn/more-pinch
Added touch identifier checking to pinchMove
2 parents 7ac5ab0 + 26c40b2 commit 7f4f106

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ Pinch events come with a special object with additional data to actually be more
8989

9090
#### Known Issues
9191

92-
* The touches array isn't ordered according to the initial pinch event's identifiers. Rare cases, where the touch order changes, can result in surprising behaviour
9392
* The pinch implementation has not been thoroughly tested
9493
* Any touch event with 3 three or more touches is completely ignored.
9594

src/Tappable.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,18 @@ var Mixin = {
128128
if (this._initialTouch) this.endTouch();
129129

130130
var touches = event.touches;
131-
var currentPinch = getPinchProps(touches); //TODO add helper function to order touches by identifier
131+
132+
if(touches.length !== 2){
133+
return this.onPinchEnd(event) // bail out before disaster
134+
}
135+
136+
var currentPinch =
137+
touches[0].identifier === this._initialPinch.touches[0].identifier && touches[1].identifier === this._initialPinch.touches[1].identifier ?
138+
getPinchProps(touches) // the touches are in the correct order
139+
: touches[1].identifier === this._initialPinch.touches[0].identifier && touches[0].identifier === this._initialPinch.touches[1].identifier ?
140+
getPinchProps(touches.reverse()) // the touches have somehow changed order
141+
:
142+
getPinchProps(touches); // something is wrong, but we still have two touch-points, so we try not to fail
132143

133144
currentPinch.displacement = {
134145
x: currentPinch.center.x - this._initialPinch.center.x,
@@ -170,9 +181,11 @@ var Mixin = {
170181
this._initialPinch = this._lastPinch = null;
171182

172183
// If one finger is still on screen, it should start a new touch event for swiping etc
173-
if (event.touches.length === 1) {
174-
this.onTouchStart(event);
175-
}
184+
// But it should never fire an onTap or onPress event.
185+
// Since there is no support swipes yet, this should be disregarded for now
186+
// if (event.touches.length === 1) {
187+
// this.onTouchStart(event);
188+
// }
176189
},
177190

178191
initScrollDetection: function() {

0 commit comments

Comments
 (0)