0.1.12 • Published 10 years ago
app-gesture-decorator v0.1.12
app-gesture-decorator
A decorator for React UI components to handle gesture recognising using HammerJS.
Features
- Allow your components to recognise the gestures on both desktop and mobile browsers.
- Prevent ghost click for your React UI components on the mobile browsers.
- Polyfill the HTMLElement with a
triggermethod that allows easierHTMLEventsandMouseEventssimulating.
Browsers Support
Prerequisites
- Install Node
>= 5.6.0
$ brew install node- Install NPM
>= 3.8.0
$ npm update -g npmInstallation
Install the plugin via NPM:
$ npm install --save app-gesture-decoratorHow To Use
Step 1: Import and use it to decorate the React component(e.g. MyComponent.jsx) using es6/es7.
import { Component } from 'react';
import AppGestureDecorator from 'app-gesture-decorator';
@AppGestureDecorator()
export default class MyComponent extends Component {
...
componentDidMount() {
this.initGestureHandler();
}
componentWillUnmount() {
this.removeGestureHandler();
}
...
}Step 2: Try out the gesture handler using props, e.g. tap. For the full list of gesture handlers, please check the Gestures section.
import { Component } from 'react';
import MyComponent from './MyComponent.jsx';
export default class MyPage extends Component {
...
handleTap(e) {
console.log(e);
}
render() {
return (
<div>
<MyComponent onTap={this.handleTap.bind(this)} />
</div>
);
}
}Gestures
onTaponDoubleTaponPanonPanStartonPanMoveonPanEndonPanCancelonPanLeftonPanRightonPanUponPanDownonPinchonPinchStartonPinchMoveonPinchEndonPinchCancelonPinchInonPinchOutonPressonPressUponRotateonRotateStartonRotateMoveonRotateEndonRotateCancelonSwipeonSwipeLeftonSwipeRightonSwipeUponSwipeDown