react-native-swipe-gestures
react-native-swipe-gestures copied to clipboard
Swipe gesture return null direction value on IOS
Here is the detail
<GestureRecognizer
onSwipe={(direction, state) => this.onSwipe(direction, state, item)}
For Onswipe
onSwipe(gestureName, gestureState, item) {
console.log("direction is="+gestureName);
let { outletInfo, assetFilter, tags, imageOlderThanHrs, locationClassification, market, imageStatus } = this.state;
const { SWIPE_LEFT, SWIPE_RIGHT } = swipeDirections;
let paramsObj = {
AssetPurityId: item.AssetPurityId ? item.AssetPurityId : 0,
AssetId: item.AssetId
};
switch (gestureName) {
case SWIPE_LEFT:
Object.assign(paramsObj, { PrevNext: 1 });
break;
case SWIPE_RIGHT:
Object.assign(paramsObj, { PrevNext: -1 });
break;
}
Gatting null direction in starting 3-4 attempt
I found the following workaround:
onSwipe={(gestureName, gestureState) => {
const {dy} = gestureState;
if (dy > 0) {
// swiped down
}
else if (dy < 0) {
// swiped up
}
}}
you can do similar logic to swiping left/right, just note the troubles of determining wether it was a horizontal or vertical swipe (you can use threshold from config)
@ReallyLiri works for me. I have handlers for swipe left and right. In addition, if direcciont === null in onSwipe, then I make an attempt to derive user intention as per your suggestion.
onSwipe={ (direction, state) => {
const {dx} = state;
if (direction === null){
if (dx > 0) {
console.log('swipe right');
}
else if (dx < 0) {
console.log('swipe left');
}
}
} }
I do feel that the UX is better this way.
I wrote some code in this issue #52 which might help these problems :)