fix(ionScroll): let zoom work on android devices

Closes #1440
This commit is contained in:
Jared Smith
2014-05-19 16:22:39 -05:00
committed by Andrew Joslin
parent 9ffca1e4eb
commit e88659c6f8
2 changed files with 43 additions and 2 deletions

View File

@@ -391,7 +391,7 @@
}
// make fake touchlist from mouse position
else {
ev.indentifier = 1;
ev.identifier = 1;
return [ev];
}
},

View File

@@ -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
);
@@ -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;
@@ -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;
@@ -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;
}
});