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

Provide deltas relative to initial onTouchStart in onSwiping callback #160

Closed
samanpwbb opened this issue Aug 5, 2019 · 3 comments
Closed

Comments

@samanpwbb
Copy link

samanpwbb commented Aug 5, 2019

Right now, a single swipe will return multiple onSwiping calls. In the app I'm building, I'm using deltaX and deltaY to show immediate feedback as user is swiping, but I don't want the deltas from every sub-event to accumulate. I wrote some code that looks like this:

let firstInitial = [];
let prevX = null;
let prevY = null;

swiping = swipeData => {
  const { deltaX, deltaY, initial } = swipeData;
  let nextY = 0,
    nextX = 0;

  // New initial value, which mean a new swipe started.
  if (!_.isEqual(firstInitial, initial) {
    firstInitial = initial;
    prevX = 0;
    prevY = 0;
  } else {
    nextX = deltaX - prevX;
    nextY = deltaY - prevY;
    prevX = deltaX;
    prevY = deltaY;
  }
  // ...use nextY and nextX in an updater function
}

It'd be nice if I didn't have to write this code:

  • Best: onSwiping could provide deltas relative to start of the swipe in addition to providing full deltas for each onSwiping event as it does now.
  • Still helpful: onSwiping could include an initialEvent so implementers could then more easily make deltas relative.
@samanpwbb samanpwbb changed the title Provide relative deltas in onSwiping callback Provide deltas relative to initial onTouchStart in onSwiping callback Aug 5, 2019
@hartzis
Copy link
Collaborator

hartzis commented Aug 9, 2019

Hey @samanpwbb, thanks for posting an issue with some ideas.

I think i'm having a hard time trying to understand exactly what you're looking for.


onSwiping could provide deltas relative to start of the swipe


onSwiping could include an initialEvent

  • Can you explain what initialEvent would contain?
    • Would it just be the first eventData object for the first onSwiping triggered?

We can also try and help clean this code up a bit.

  // New initial value, which mean a new swipe started.
  if (!_.isEqual(firstInitial, initial) {

By introducing a first boolean? That would be true when it's the first event.


I'm absolutely open to taking a look at and considering a PR for what you're looking for and/or I can try and create a PR if we can clarify these a bit more.

Cheers!

@samanpwbb
Copy link
Author

samanpwbb commented Aug 9, 2019

Thanks for getting back to me!

Do you want the delta(s) from the previous onSwiping in the next onSwiping

After fiddling with my code a bit, I realize that it's necessary to throttle the onSwiping events, so deltas from previous events wouldn't help me unless react-swipeable did the throttling internally. It'd be awesome if it did, but that really expands the scope of this feature request 😄.

Your last suggestion is my favorite:

By introducing a first boolean? That would be true when it's the first event.

I think we could close this issue if just this feature was added. I'll try to find the time to put up a PR for you.

@hartzis hartzis mentioned this issue Aug 16, 2019
2 tasks
@hartzis
Copy link
Collaborator

hartzis commented Nov 29, 2019

Closing with #162

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

No branches or pull requests

2 participants