Hammer.JS for React Native. HammerJS is a javascript library for multi-touch gestures.
npm install --save react-native-hammerjs
import { Hammer, injectHammer } from 'react-native-hammerjs';
class YourComponent extends React.Component {
componentDidMount() {
const mc = this.props.hammer;
mc.add( new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 }) );
mc.on('pan', e => {
console.log('pan', e);
});
}
render() {
const connectEventHandlers = this.props.connectEventHandlers;
return connectEventHandlers(
<View>
<Content />
</View>
);
}
}
export default injectHammer(YourComponent);
For more examples, check out examples folder
This module exposes:
Hammer
: Hammer class as inHammerJS
injectHammer
: A function that creates a Higher Order Component that wrapsYourComponent
and injects 2 props:
hammer
: aHammer.Manager
object.connectEventHandlers
: a function connects native gesture responders withHammer.Manager
object.
PRs are welcome!