Skip to content

Commit

Permalink
add_touchPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
arusantimo committed Aug 11, 2017
1 parent a677861 commit 164f2a5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/vx-event/src/touchPoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Point } from '@vx/point';
export default function touchPoint(node, event) {
if (!node) return;
const svg = node.ownerSVGElement || node;
if (svg.createSVGPoint) {
let point = svg.createSVGPoint();
point.x = event.changedTouches[0].clientX;
point.y = event.changedTouches[0].clientY;
point = point.matrixTransform(node.getScreenCTM().inverse());
return new Point({
x: point.x,
y: point.y
});
}
const rect = node.getBoundingClientRect();
return new Point({
x: event.changedTouches[0].clientX - rect.left - node.clientLeft,
y: event.changedTouches[0].clientY - rect.top - node.clientTop
});
}

0 comments on commit 164f2a5

Please sign in to comment.