Swipe not detect properly for left and right
ydv0121 opened this issue · 10 comments
when i am trying to swipe right it always gives me SWIPE_LEFT..anyone know how to fix it?
Same problem, can anyone know how to fix it.
Same problem here too.
Same Problem Here. Is there any wayout?
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)
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?
where should i add these code?
I have added this code to be the function that actually receives 'dx' and 'dy' from the component.
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}>
@JuEunSung is it working for you?
@JuEunSung is it working for you?
yes my case was up-down problem..
(sorry english clumsy)
Did anyone find solution?