From 25fd30a2fa07a5629f37108691e7b26174acd95f Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Sun, 23 Sep 2018 22:07:00 -0400 Subject: [PATCH] pinch scale for mobile browsers that don't support it (Chrome) --- src/onTap.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/onTap.js b/src/onTap.js index b15d1d9..edef3bf 100644 --- a/src/onTap.js +++ b/src/onTap.js @@ -124,6 +124,7 @@ export default class OnTap { if (event.touches.length > 1) { this.state.pinching = true; + this.state.scaleStart = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2)); clearTimeout(this.state.pressTO); } @@ -198,6 +199,7 @@ export default class OnTap { if (event.touches.length === 0) { this.state.pinching = false; + this.state.scaleStart = null; this.state.moving = null; this.state.lastX = null; this.state.lastY = null; @@ -236,6 +238,10 @@ export default class OnTap { if (this.state.tapStartTime) { const touches = [...event.touches]; + event.scale = event.scale ? event.scale : + touches.length < 2 ? 1 : + Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2)) / this.state.scaleStart; + Object.assign(event, { offsetX: touches.reduce((memo, touch) => memo + touch.pageX, 0) / touches.length, offsetY: touches.reduce((memo, touch) => memo + touch.pageY, 0) / touches.length,