react-hammerjs icon indicating copy to clipboard operation
react-hammerjs copied to clipboard

Suggestion: drop the `vertical` prop and replace it with a `direction` prop

Open bramus opened this issue 10 years ago • 3 comments

I find the vertical prop somewhat confusing as it does not actually limit Hammer to vertical gestures, but to gestures in all directions.

From the code:

// Hammer.js, L53
    if (props.vertical) {
        hammer.get('pan').set({direction: Hammer.DIRECTION_ALL});
        hammer.get('swipe').set({direction: Hammer.DIRECTION_ALL});
    } else {
        hammer.get('pan').set({direction: Hammer.DIRECTION_HORIZONTAL});
        hammer.get('swipe').set({direction: Hammer.DIRECTION_HORIZONTAL});
    }

Given the Hammer.DIRECTION_* constants it'd be better to allow one to use those by means of a direction prop.

Example usage would be this:

var Hammer = require('hammerjs');
var ReactHammer = require('react-hammerjs');

<ReactHammer onSwipe={handleSwipe} direction="{Hammer.DIRECTION_VERTICAL}"><div>Swipe Me</div></ReactHammer>

(note that I also import Hammer itself, to gain access to the contstants. These could - for example - also be exposed on react-hammerjs)

bramus avatar Apr 15 '16 13:04 bramus

+1

silentcloud avatar Jul 07 '16 03:07 silentcloud

I'm having a hard time implementing this with version 0.5.0 not sure what I'm missing. Do you have a more explicit example with the merged PR? Also the fallback of vertical breaks completely with the error: Uncaught ReferenceError: direction is not defined (I am working with this for onPan)

I get the error Uncaught ReferenceError: direction is not defined when defining direction={...} as well.

shalanah avatar Jul 25 '16 20:07 shalanah

@shalanah look at this:

https://github.com/react-component/swipeout/blob/master/src/Swipeout.web.js#L210

silentcloud avatar Aug 07 '16 13:08 silentcloud