react-native-swipe-gestures icon indicating copy to clipboard operation
react-native-swipe-gestures copied to clipboard

Swipe gesture return null direction value on IOS

Open ManishKumarPandia opened this issue 5 years ago • 3 comments

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

ManishKumarPandia avatar Jul 23 '19 08:07 ManishKumarPandia

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 avatar Nov 30 '19 17:11 ReallyLiri

@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.

nerycordova avatar May 24 '20 22:05 nerycordova

I wrote some code in this issue #52 which might help these problems :)

Diabl0269 avatar Jun 06 '20 08:06 Diabl0269