react-gesture-handler
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "react-gesture-handler", | ||
"title": "react-gesture-handler", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "React component to detect touch gestures", | ||
@@ -30,3 +30,5 @@ "keywords": [ | ||
"build": "rm -rf lib/ && tsc", | ||
"build-publish": "npm run build && cp package.json lib/package.json && cp README.md lib/README.md && cd lib && npm publish" | ||
"copy-files": "cp package.json lib/package.json && cp README.md lib/README.md", | ||
"build-publish": "npm run build && npm run copy-files && cd lib && npm run publish", | ||
"update-version": "node update-version.js" | ||
}, | ||
@@ -33,0 +35,0 @@ "dependencies": { |
@@ -1,14 +0,6 @@ | ||
# react-gesture-handler | ||
# React Gesture Handler | ||
React component to detect touch gestures. It's a react port of [hammerjs](https://hammerjs.github.io/) :) | ||
# Install | ||
``` | ||
npm i react-gesture-handler hammerjs --save | ||
npm i @types/hammerjs --save-dev | ||
``` | ||
# Events | ||
## Events | ||
- Pan | ||
@@ -21,36 +13,47 @@ - Pinch | ||
# Usage | ||
Example: | ||
## Getting Started | ||
### Installing | ||
``` | ||
import { React } from 'react'; | ||
import { Gestures } from 'react-gesture-handler'; | ||
npm i react-gesture-handler hammerjs --save | ||
npm i @types/hammerjs --save-dev | ||
``` | ||
const MyComponent = () =>{ | ||
const [eventType, setEventType] = React.useState<string>(''); | ||
### Usage | ||
[Example with pan](https://codesandbox.io/s/react-gesture-handler-simple-example-with-pan-d0b7t) | ||
const handleGesture = (event: HammerInput) => setEventType(event.type); | ||
``` | ||
import * as React from "react"; | ||
import { Gestures } from "react-gesture-handler"; | ||
return ( | ||
<Gestures | ||
recognizers={{ | ||
Pan: { | ||
options: { direction: Hammer.DIRECTION_ALL, threshold: 0 }, | ||
events: { | ||
panleft: handleGesture, | ||
panright: handleGesture, | ||
panup: handleGesture, | ||
pandown: handleGesture | ||
} | ||
} | ||
}} | ||
> | ||
<div> | ||
<p>Gesture Section</p> | ||
{eventType && `This is ${eventType}`} | ||
</div> | ||
</Gestures> | ||
); | ||
} | ||
const MyComponent = () => { | ||
const [eventType, setEventType] = React.useState<string>(""); | ||
const handleGesture = (event: HammerInput) => setEventType(event.type); | ||
return ( | ||
<Gestures | ||
recognizers={{ | ||
Pan: { | ||
events: { | ||
panleft: handleGesture, | ||
panright: handleGesture, | ||
panup: handleGesture, | ||
pandown: handleGesture | ||
} | ||
} | ||
}} | ||
> | ||
<div> | ||
<h1>Gesture Section {eventType && ` - This is ${eventType}`}</h1> | ||
</div> | ||
</Gestures> | ||
); | ||
}; | ||
``` | ||
## License | ||
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/elsa-santos/react-gesture-handler/blob/master/LICENSE) file for details |
12514
59