Skip to content

Commit e88659c

Browse files
jedibatmanajoslin
authored andcommitted
fix(ionScroll): let zoom work on android devices
Closes #1440
1 parent 9ffca1e commit e88659c

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

js/utils/gestures.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
}
392392
// make fake touchlist from mouse position
393393
else {
394-
ev.indentifier = 1;
394+
ev.identifier = 1;
395395
return [ev];
396396
}
397397
},

js/views/scrollView.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
848848

849849
self.hintResize();
850850
self.scrollBy(
851-
e.wheelDeltaX/self.options.wheelDampen,
851+
e.wheelDeltaX/self.options.wheelDampen,
852852
-e.wheelDeltaY/self.options.wheelDampen
853853
);
854854

@@ -1585,6 +1585,9 @@ ionic.views.Scroll = ionic.views.View.inherit({
15851585
self.__initialTouchLeft = currentTouchLeft;
15861586
self.__initialTouchTop = currentTouchTop;
15871587

1588+
// Store initial touchList for scale calculation
1589+
self.__initialTouches = touches;
1590+
15881591
// Store current zoom level
15891592
self.__zoomLevelStart = self.__zoomLevel;
15901593

@@ -1644,6 +1647,11 @@ ionic.views.Scroll = ionic.views.View.inherit({
16441647
if (touches.length === 2) {
16451648
currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2;
16461649
currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2;
1650+
1651+
// Calculate scale when not present and only when touches are used
1652+
if (!scale && self.options.zooming) {
1653+
scale = self.__getScale(self.__initialTouches, touches);
1654+
}
16471655
} else {
16481656
currentTouchLeft = touches[0].pageX;
16491657
currentTouchTop = touches[0].pageY;
@@ -2255,6 +2263,39 @@ ionic.views.Scroll = ionic.views.View.inherit({
22552263
}
22562264
}
22572265
}
2266+
},
2267+
2268+
2269+
/**
2270+
* calculate the distance between two touches
2271+
* @param {Touch} touch1
2272+
* @param {Touch} touch2
2273+
* @returns {Number} distance
2274+
*/
2275+
__getDistance: function getDistance(touch1, touch2) {
2276+
var x = touch2.pageX - touch1.pageX,
2277+
y = touch2.pageY - touch1.pageY;
2278+
return Math.sqrt((x*x) + (y*y));
2279+
},
2280+
2281+
2282+
/**
2283+
* calculate the scale factor between two touchLists (fingers)
2284+
* no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
2285+
* @param {Array} start
2286+
* @param {Array} end
2287+
* @returns {Number} scale
2288+
*/
2289+
__getScale: function getScale(start, end) {
2290+
2291+
var self = this;
2292+
2293+
// need two fingers...
2294+
if(start.length >= 2 && end.length >= 2) {
2295+
return self.__getDistance(end[0], end[1]) /
2296+
self.__getDistance(start[0], start[1]);
2297+
}
2298+
return 1;
22582299
}
22592300
});
22602301

0 commit comments

Comments
 (0)