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

Swipe not detect properly for left and right #52

Open
ydv0121 opened this issue Feb 10, 2020 · 10 comments
Open

Swipe not detect properly for left and right #52

ydv0121 opened this issue Feb 10, 2020 · 10 comments

Comments

@ydv0121
Copy link

ydv0121 commented Feb 10, 2020

when i am trying to swipe right it always gives me SWIPE_LEFT..anyone know how to fix it?

@ghost
Copy link

ghost commented Feb 27, 2020

Same problem, can anyone know how to fix it.

@Akhilpilli
Copy link

Same problem here too.

@aliwaqar981
Copy link

Same Problem Here. Is there any wayout?

@Diabl0269
Copy link

Diabl0269 commented Jun 6, 2020

Hey, i have been dealing with the same issue, something in the code doesn't detect the swipe correctly.
I have used the 'onSwipe' attribute which gets a 'state' object as it's second argument, taking from it 'dx' and 'dy' i wrote these 4 lines of code which works great for me so far for detecting the swipe side.
Hope this will help others :)

const figureHorizontalDirection = (delta) => (delta > 0 ? 'SWIPE_RIGHT' : 'SWIPE_LEFT')
const figureVerticalDirection = (delta) => (delta > 0 ? 'SWIPE_DOWN' : 'SWIPE_UP')

export default ({ dx, dy }) =>
  Math.abs(dx) > Math.abs(dy) ? figureHorizontalDirection(dx) : figureVerticalDirection(dy)

@kuldeepworkid
Copy link

Hey, i have been dealing with the same issue, something in the code doesn't detect the swipe correctly.
I have used the 'onSwipe' attribute which gets a 'state' object as it's second argument, taking from it 'dx' and 'dy' i wrote these 4 lines of code which works great for me so far for detecting the swipe side.
Hope this will help others :)

const figureHorizontalDirection = (delta) => (delta > 0 ? 'SWIPE_RIGHT' : 'SWIPE_LEFT')
const figureVerticalDirection = (delta) => (delta > 0 ? 'SWIPE_DOWN' : 'SWIPE_UP')

export default ({ dx, dy }) =>
  Math.abs(dx) > Math.abs(dy) ? figureHorizontalDirection(dx) : figureVerticalDirection(dy)

where should i add these code?

@Diabl0269
Copy link

Diabl0269 commented Jul 14, 2020

where should i add these code?

I have added this code to be the function that actually receives 'dx' and 'dy' from the component.

@JuEunSung
Copy link

JuEunSung commented Nov 24, 2020

thank you @Diabl0269 Diabl0269

i try this

const direction = () => {
      const figureHorizontalDirection = (delta) => (delta > 0 ? 'SWIPE_RIGHT' : 'SWIPE_LEFT');
      const figureVerticalDirection = (delta) => (delta > 0 ? 'SWIPE_DOWN' : 'SWIPE_UP');

      const dx = this.endX - this.startX;
      const dy = this.endY - this.startY;

      return Math.abs(dx) > Math.abs(dy) ? figureHorizontalDirection(dx) : figureVerticalDirection(dy);
};
<GestureRecognizer
    onTouchStart={(event) => {
        this.startX = event.nativeEvent.pageX;
        this.startY = event.nativeEvent.pageY;
    }}
    onTouchEnd={(event) => {
        this.endX = event.nativeEvent.pageX;
        this.endY = event.nativeEvent.pageY;

        const d = direction();

        if (d === 'SWIPE_UP') {
            this.onSwipeUp();
        } else if (d === 'SWIPE_DOWN') {
            this.onSwipeDown();
        }
    }}
    style={style.swipe_box}>

@ydv0121
Copy link
Author

ydv0121 commented Nov 24, 2020

@JuEunSung is it working for you?

@JuEunSung
Copy link

@JuEunSung is it working for you?

yes my case was up-down problem..
(sorry english clumsy)

@dhameliyadharmesh
Copy link

Did anyone find solution?

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

7 participants