[improvement] ImagePreview: optimize static methods (#2396)

This commit is contained in:
neverland
2018-12-27 22:05:22 +08:00
committed by GitHub
parent b81dff92fe
commit f5e2ab063c
2 changed files with 18 additions and 18 deletions
+11 -11
View File
@@ -51,6 +51,15 @@ import { range } from '../utils';
const MAX_ZOOM = 3;
const MIN_ZOOM = 1 / 3;
function getDistance(touches) {
return Math.sqrt(
Math.abs(
(touches[0].clientX - touches[1].clientX) *
(touches[0].clientY - touches[1].clientY)
)
);
}
export default create({
name: 'image-preview',
@@ -156,15 +165,6 @@ export default create({
}
},
getDistance(touches) {
return Math.sqrt(
Math.abs(
(touches[0].clientX - touches[1].clientX) *
(touches[0].clientY - touches[1].clientY)
)
);
},
startMove(event) {
const image = event.currentTarget;
const rect = image.getBoundingClientRect();
@@ -183,7 +183,7 @@ export default create({
this.moving = false;
this.zooming = true;
this.startScale = this.scale;
this.startDistance = this.getDistance(event.touches);
this.startDistance = getDistance(event.touches);
},
onTouchStart(event) {
@@ -213,7 +213,7 @@ export default create({
}
if (this.zooming && touches.length === 2) {
const distance = this.getDistance(touches);
const distance = getDistance(touches);
const scale = (this.startScale * distance) / this.startDistance;
this.scale = range(scale, MIN_ZOOM, MAX_ZOOM);
}