Skip to content

Commit

Permalink
fix(ionScroll): let zoom work on android devices
Browse files Browse the repository at this point in the history
Closes #1440
  • Loading branch information
jedibatman authored and ajoslin committed Jun 4, 2014
1 parent 9ffca1e commit e88659c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/utils/gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@
}
// make fake touchlist from mouse position
else {
ev.indentifier = 1;
ev.identifier = 1;
return [ev];
}
},
Expand Down
43 changes: 42 additions & 1 deletion js/views/scrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ ionic.views.Scroll = ionic.views.View.inherit({

self.hintResize();
self.scrollBy(
e.wheelDeltaX/self.options.wheelDampen,
e.wheelDeltaX/self.options.wheelDampen,
-e.wheelDeltaY/self.options.wheelDampen
);

Expand Down Expand Up @@ -1585,6 +1585,9 @@ ionic.views.Scroll = ionic.views.View.inherit({
self.__initialTouchLeft = currentTouchLeft;
self.__initialTouchTop = currentTouchTop;

// Store initial touchList for scale calculation
self.__initialTouches = touches;

// Store current zoom level
self.__zoomLevelStart = self.__zoomLevel;

Expand Down Expand Up @@ -1644,6 +1647,11 @@ ionic.views.Scroll = ionic.views.View.inherit({
if (touches.length === 2) {
currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2;
currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2;

// Calculate scale when not present and only when touches are used
if (!scale && self.options.zooming) {
scale = self.__getScale(self.__initialTouches, touches);
}
} else {
currentTouchLeft = touches[0].pageX;
currentTouchTop = touches[0].pageY;
Expand Down Expand Up @@ -2255,6 +2263,39 @@ ionic.views.Scroll = ionic.views.View.inherit({
}
}
}
},


/**
* calculate the distance between two touches
* @param {Touch} touch1
* @param {Touch} touch2
* @returns {Number} distance
*/
__getDistance: function getDistance(touch1, touch2) {
var x = touch2.pageX - touch1.pageX,
y = touch2.pageY - touch1.pageY;
return Math.sqrt((x*x) + (y*y));
},


/**
* calculate the scale factor between two touchLists (fingers)
* no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
* @param {Array} start
* @param {Array} end
* @returns {Number} scale
*/
__getScale: function getScale(start, end) {

var self = this;

// need two fingers...
if(start.length >= 2 && end.length >= 2) {
return self.__getDistance(end[0], end[1]) /
self.__getDistance(start[0], start[1]);
}
return 1;
}
});

Expand Down

0 comments on commit e88659c

Please sign in to comment.