voronianski / swipe-js-iso

Universal (a.k.a isomorphic) version of Swipe.js
https://www.npmjs.com/package/swipe-js-iso
MIT License
188 stars 57 forks source link

attempt event #3

Closed violinchris closed 6 years ago

violinchris commented 8 years ago

First, thanks for the fork as the original swipejs isn't active apparently. There seems to be one other fork at https://github.com/lyfeyaj/swipe, so I'm not sure of the proper place to discuss this, but since I am using react-swipe, I am starting here.

I am using react-swipe and swipe-js-iso for a swipe views sort of ui with sliding tab. I need an attempt event. This would be when the user tries to swipe to the next/previous slide and there is either success or failure. Having this would allow me to do take care of a transition on something outside of swipejs, like my sliding tab. Currently, there is only the success-only callback.

Of course I could do my own touchstart and touchend event in my code, check to see if it is a scroll or swipe, maybe other checks, but it seems to me that other people may need this attempt event. I placed some code at the end of the if (!isScrolling) check in the end event.

if (!isScrolling) { // if not scrolling vertically 
    // lots of ifs, elses, etc. ... 
    // at the end is best place for attempt event? 
    options.attempt && options.attempt(index, slides[index]); 
}

It does what I want, but I am curious to know if there is another way to do this without changing swipe-js-iso.

I also found a need for the slide index as a second parameter in the sliding function, but I will do a separate issue for this after the attempt issue is resolved.

Chris