Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused by deltaX and deltaY #157

Closed
lhnrd opened this issue Jul 24, 2019 · 5 comments · Fixed by #200
Closed

Confused by deltaX and deltaY #157

lhnrd opened this issue Jul 24, 2019 · 5 comments · Fixed by #200
Assignees
Milestone

Comments

@lhnrd
Copy link

lhnrd commented Jul 24, 2019

Documentation:

{
  event,          // source event
  deltaX,         // x offset (current.x - initial.x)
  deltaY,         // y offset (current.y - initial.y)
  absX,           // absolute deltaX
  absY,           // absolute deltaY
  velocity,       // √(absX^2 + absY^2) / time
  dir,            // direction of swipe (Left|Right|Up|Down)
}

Codebase:

const { clientX, clientY } = event.touches ? event.touches[0] : event
const [x, y] = rotateXYByAngle([clientX, clientY], props.rotationAngle)
const deltaX = state.xy[0] - x
const deltaY = state.xy[1] - y

My question here is, are clientX and clientY the current x and y coordinates of the mouse?
The docs says current.x minus initial.x, I was expecting that a mouse movement from left to right returns a positive value, but it's the opposite.

Am I getting something wrong here?

@hartzis hartzis added this to the v6 milestone Jul 29, 2019
@hartzis
Copy link
Collaborator

hartzis commented Jul 29, 2019

@r-inaldi Thank you for posting the issue, you've absolutely found a discrepancy. The readme should say initial - current, I'll get a small PR to update the docs. At least it looks like we've been consistent between v4 & v5.

I think you're absolutely correct and we should be doing current - initial and I think that's why the docs say that, but it looks like we just "copied" what we had in v4 to v5 in the code.

Going to make a note to make this change for v6 when we drop the <Swipeable /> component.

@hartzis
Copy link
Collaborator

hartzis commented Jul 29, 2019

@r-inaldi a side note, i'll try to merge in #151 soon which adds [initialX, initialY] as eventData.initial and that could be used to derive the "correct" delta values you're looking for.

@lhnrd
Copy link
Author

lhnrd commented Jul 29, 2019

Thanks for the fix @hartzis. Wasn't sure if I was getting something wrong, started to really doubt my knowledge about page coordinates. 😂

@psikoi
Copy link

psikoi commented Sep 27, 2019

I believe this should be closed?

@hartzis
Copy link
Collaborator

hartzis commented Sep 27, 2019

@psikoi thanks for the :poke:, i was keeping it open till i merged and deployed #162

@upatel32 upatel32 self-assigned this Aug 18, 2020
@upatel32 upatel32 linked a pull request Aug 20, 2020 that will close this issue
@hartzis hartzis closed this as completed Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants