# react-hammerjs

> ReactJS / HammerJS integration. Support touch events in your React app.

Latest version **1.0.1** (published 2017-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-hammerjs
pnpm add react-hammerjs
yarn add react-hammerjs
bun add react-hammerjs
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-10-24 |
| First published | 2014-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/react-hammerjs) |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 924 |
| Author | Jed Watson |
| Maintainers | jedwatson |
| Keywords | react, react-component, tap, tappable, touch, hammer, hammerjs, mobile |

## Links

- npm: https://www.npmjs.com/package/react-hammerjs
- Repository: https://github.com/JedWatson/react-hammerjs
- Homepage: https://github.com/JedWatson/react-hammerjs#readme
- Issues: https://github.com/JedWatson/react-hammerjs/issues
- npm.io page: https://npm.io/package/react-hammerjs

## Dependencies (1)

- [hammerjs](https://npm.io/package/hammerjs.md) ^2.0.8

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-10-24
- 1.0.0 — 2017-10-24
- 0.5.0 — 2016-07-08
- 0.4.6 — 2016-04-15
- 0.4.5 — 2015-12-26
- 0.4.3 — 2015-11-26
- 0.4.2 — 2015-10-27
- 0.4.1 — 2015-10-18
- 0.4.0 — 2015-10-11
- 0.3.0 — 2015-09-21
- 0.2.5 — 2015-09-05
- 0.2.4 — 2015-08-22
- 0.2.3 — 2015-08-20
- 0.2.2 — 2015-04-13
- 0.2.1 — 2015-04-04
- … 7 more at https://npm.io/package/react-hammerjs/versions

## README

React-HammerJS
==============

[ReactJS](http://facebook.github.io/react/) / [HammerJS](http://hammerjs.github.io) integration. Support touch events in your React app.

If you're looking for native tap event handling in ReactJS, check out my [react-tappable](https://github.com/JedWatson/react-tappable) package.


## Installation

The easiest way to use React-HammerJS is to install it from NPM and include it in your own React build process (using [Browserify](http://browserify.org), etc).

You can also use the standalone build by including `dist/hammer.js` in your page. If you use this, make sure you have already included React, and it is available as a global variable.

```
npm install react-hammerjs --save
```


## Usage

React-HammerJS wraps a React component, binding Hammer events to it so it can fire the handlers specified.

## Properties

### Event Listener properties
* `onTap`
* `onDoubleTap`
* `onPan`
* `onPanCancel`
* `onPanEnd`
* `onPanStart`
* `onPinch`
* `onPinchCancel`
* `onPinchEnd`
* `onPinchIn`
* `onPinchOut`
* `onPinchStart`
* `onPress`
* `onPressUp`
* `onRotate`
* `onRotateCancel`
* `onRotateEnd`
* `onRotateMove`
* `onRotateStart`
* `onSwipe`
* `action` - like the `onTap` event handler but will also be fired `onPress`.

### Behavior properties
* `direction` - (string) `'DIRECTION_ALL'` | `'DIRECTION_HORIZONTAL'` | `'DIRECTION_VERTICAL'`.  Used to restrict the `pan` and `swipe` direction. These string values may also work: `'DIRECTION_NONE'` |`'DIRECTION_LEFT'` | `'DIRECTION_RIGHT'` | `'DIRECTION_UP'` | `'DIRECTION_DOWN'`.

* `options` - can be used to configure the Hammer manager. These properties will be merged with the default ones.

### Example

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

// Default options
<Hammer onTap={handleTap} onSwipe={handleSwipe}><div>Tap Me</div></Hammer>

// Custom options
var options = {
    touchAction:'compute',
    recognizers: {
        tap: {
            time: 600,
            threshold: 100
        }
    }
};

<Hammer onTap={handleTap} options={options}><div>Tap Me</div></Hammer>
```

# Disabled Events

As a default, the `pinch` and `rotate` events are disabled in hammer.js, as they would make actions on an element "blocking". You may enable these events using the options object which is a attribute on the react `<Hammer>` element.

For example, to activate the `pinch` event on a `canvas` element:

```
<Hammer
    onPinch={handlePinch}
    options={{
       recognizers: {
          pinch: { enable: true }
       }
    }}>
    <canvas></canvas>
</Hammer>
```

Disabled events are detailed in the hammer.js api documentation:
- http://hammerjs.github.io/recognizer-rotate/
- http://hammerjs.github.io/recognizer-pinch/

# License

MIT Licensed. Copyright (c) Jed Watson 2017.

---
_Source: https://npm.io/package/react-hammerjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
