Skip to content

Commit

Permalink
Check direction of swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
gaer87 committed Apr 27, 2019
1 parent a13c540 commit 22056a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/js/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class SwipeToDelete extends React.Component {
this.onInteract = e => {
el.removeEventListener(this.device.getStartEventName(), this.onInteract, false);
this.model.startX = this.device.getPageX(e);
this.model.startY = this.device.getPageY(e);
resolve();
};

Expand All @@ -85,9 +86,15 @@ export default class SwipeToDelete extends React.Component {

moveAt(e) {
const target = this.regionContent.firstChild;
const res = this.device.getPageX(e) - this.model.startX;
const resX = this.device.getPageX(e) - this.model.startX;
const resY = this.device.getPageY(e) - this.model.startY;

target.style.left = `${res}px`;
if (Math.abs(resX) <= Math.abs(resY)) {
console.info('F');
return;
}

target.style.left = `${resX}px`;
}

callMoveCB(e) {
Expand Down
4 changes: 4 additions & 0 deletions src/js/utils/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default class Device {
class Touch extends Device {
getPageX(e) { return e.targetTouches[0].pageX; }

getPageY(e) { return e.targetTouches[0].pageY; }

getStartEventName() { return 'touchstart'; }

getInteractEventName() { return 'touchmove'; }
Expand All @@ -17,6 +19,8 @@ class Touch extends Device {
class Mouse extends Device {
getPageX(e) { return e.pageX; }

getPageY(e) { return e.pageY; }

getStartEventName() { return 'mousedown'; }

getInteractEventName() { return 'mousemove'; }
Expand Down

0 comments on commit 22056a9

Please sign in to comment.