2
Vote

Swipe sensibility range

description

Hi, I'm having some issue with swipes events.
I think the problem is inside the _onTouchend() function on the _sType switch.

Here your code:
_oDetails.type = [
'swipe',
((_oDetails.delta[0].lastX != 0) ? ((_oDetails.delta[0].lastX > 0) ? 'right' : 'left') : ''),
((_oDetails.delta[0].lastY != 0) ? ((_oDetails.delta[0].lastY > 0) ? 'down' : 'up') :'')].join('');
Here my testing code:
_oDetails.type = [
'swipe',
(_oDetails.delta[0].lastX > 20 ? 'right' : (_oDetails.delta[0].lastX < -20 ? 'left' : '')),
(_oDetails.delta[0].lastY > 20 ? 'down' : (_oDetails.delta[0].lastY < -20 ? 'up' : ''))].join('');
because in a real world application it's very hard move a finger just left, right, top or bottom.
So it's very difficult to trigger events like swipeleft, swiperight, swipeup or swipedown, but is more probable to trigger the equivalent swipeleft(up|down), swiperight(up|down) etc...

What do you think about?

comments

bigluck wrote Nov 15, 2012 at 12:41 AM

Here there is a more accurate fix:

case 'swipeup':
case 'swiperightup':
case 'swiperight':
case 'swiperightdown':
case 'swipedown':
case 'swipeleftdown':
case 'swipeleft':
case 'swipeleftup':
if ( _bHasTouches && _bHasMoved === true && _bHasSwipeGesture===true) {
    _bIsSwipe = true;
    /* My alternative solution */
    var tollerance = 0.2,
        lastX = _oDetails.delta[0].lastX,
        lastY = _oDetails.delta[0].lastY,
        absLastX = Math.abs(lastX),
        absLastY = Math.abs(lastY);

    _oDetails.type = 'swipe'+
        (absLastX/absLastY > tollerance ? (lastX < 0 ? 'left' : 'right') : '')+
        (absLastY/absLastX > tollerance ? (lastY < 0 ? 'up' : 'down') : '');
    if (_sType == _oDetails.type)
        _$element.triggerHandler(_oDetails.type, _oDetails);
    /*** MIA MODIFICA ***/
}

wrote Feb 19, 2013 at 8:36 PM

wrote Feb 22, 2013 at 1:36 AM