react-native-hammerjs
v2.0.11
Published
HammerJS for React Native
Downloads
9
Readme
Hammer Native
Hammer.JS for React Native. HammerJS is a javascript library for multi-touch gestures.
Installation
npm install --save react-native-hammerjs
Usage
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.
Contributing
PRs are welcome!