1 | # rc-gesture
|
2 | ---
|
3 |
|
4 | Support gesture for react component, inspired by [hammer.js](https://github.com/hammerjs/hammer.js) and [AlloyFinger](https://github.com/AlloyTeam/AlloyFinger).
|
5 |
|
6 | [![NPM version][npm-image]][npm-url]
|
7 | [![build status][travis-image]][travis-url]
|
8 | [![Test coverage][coveralls-image]][coveralls-url]
|
9 | [![gemnasium deps][gemnasium-image]][gemnasium-url]
|
10 | [![node version][node-image]][node-url]
|
11 | [![npm download][download-image]][download-url]
|
12 |
|
13 | [npm-image]: http://img.shields.io/npm/v/rc-gesture.svg?style=flat-square
|
14 | [npm-url]: http://npmjs.org/package/rc-gesture
|
15 | [travis-image]: https://img.shields.io/travis/react-component/gesture.svg?style=flat-square
|
16 | [travis-url]: https://travis-ci.org/react-component/gesture
|
17 | [coveralls-image]: https://img.shields.io/coveralls/react-component/gesture.svg?style=flat-square
|
18 | [coveralls-url]: https://coveralls.io/r/react-component/gesture?branch=master
|
19 | [gemnasium-image]: http://img.shields.io/gemnasium/react-component/gesture.svg?style=flat-square
|
20 | [gemnasium-url]: https://gemnasium.com/react-component/gesture
|
21 | [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
|
22 | [node-url]: http://nodejs.org/download/
|
23 | [download-image]: https://img.shields.io/npm/dm/rc-gesture.svg?style=flat-square
|
24 | [download-url]: https://npmjs.org/package/rc-gesture
|
25 |
|
26 | ## Screenshots
|
27 |
|
28 |
|
29 | ## Features
|
30 |
|
31 |
|
32 |
|
33 | ## Install
|
34 |
|
35 | ```bash
|
36 | npm install --save rc-gesture
|
37 | ```
|
38 |
|
39 | [![rc-gesture](https://nodei.co/npm/rc-gesture.png)](https://npmjs.org/package/rc-gesture)
|
40 |
|
41 | ## Usage
|
42 |
|
43 | ```tsx
|
44 | import Gesture from 'rc-gesture';
|
45 |
|
46 | ReactDOM.render(
|
47 | <Gesture
|
48 | onTap={(gestureStatus) => { console.log(gestureStatus); }}
|
49 | >
|
50 | <div>container</div>
|
51 | </Gesture>,
|
52 | container);
|
53 | ```
|
54 |
|
55 |
|
56 | ## API
|
57 |
|
58 | all callback funtion will have one parammeter: `type GestureHandler = (s: IGestureStatus) => void;`
|
59 |
|
60 | - gesture: the rc-gesture state object, which contain all information you may need, see [gesture](#gesture)
|
61 |
|
62 | ### props:
|
63 |
|
64 | #### common props
|
65 | <table class="table table-bordered table-striped">
|
66 | <thead>
|
67 | <tr>
|
68 | <th style="width: 100px;">name</th>
|
69 | <th style="width: 50px;">type</th>
|
70 | <th>default</th>
|
71 | <th>description</th>
|
72 | </tr>
|
73 | </thead>
|
74 | <tbody>
|
75 | <tr>
|
76 | <td>direction</td>
|
77 | <td>string</td>
|
78 | <th>`all`</th>
|
79 | <td>control the allowed gesture direction, could be `['all', 'vertical', 'horizontal']`</td>
|
80 | </tr>
|
81 | </table>
|
82 |
|
83 | #### Tap & Press
|
84 | <table class="table table-bordered table-striped">
|
85 | <thead>
|
86 | <tr>
|
87 | <th style="width: 100px;">name</th>
|
88 | <th style="width: 50px;">type</th>
|
89 | <th>default</th>
|
90 | <th>description</th>
|
91 | </tr>
|
92 | </thead>
|
93 | <tbody>
|
94 | <tr>
|
95 | <td>onTap</td>
|
96 | <td>function</td>
|
97 | <th></th>
|
98 | <td>single tap callback</td>
|
99 | </tr>
|
100 | <tr>
|
101 | <td>onPress</td>
|
102 | <td>function</td>
|
103 | <th></th>
|
104 | <td>long tap callback</td>
|
105 | </tr>
|
106 | <tr>
|
107 | <td>onPressOut</td>
|
108 | <td>function</td>
|
109 | <th></th>
|
110 | <td>long tap end callback</td>
|
111 | </tr>
|
112 | </table>
|
113 |
|
114 | #### Swipe
|
115 | <table class="table table-bordered table-striped">
|
116 | <thead>
|
117 | <tr>
|
118 | <th style="width: 100px;">name</th>
|
119 | <th style="width: 50px;">type</th>
|
120 | <th>default</th>
|
121 | <th>description</th>
|
122 | </tr>
|
123 | </thead>
|
124 | <tbody>
|
125 | <tr>
|
126 | <td>onSwipe</td>
|
127 | <td>function</td>
|
128 | <th></th>
|
129 | <td>swipe callback, will triggered at the same time of all of below callback</td>
|
130 | </tr>
|
131 | <tr>
|
132 | <td>onSwipeLeft</td>
|
133 | <td>function</td>
|
134 | <th></th>
|
135 | <td>swipe left callback</td>
|
136 | </tr>
|
137 | <tr>
|
138 | <td>onSwipeRight</td>
|
139 | <td>function</td>
|
140 | <th></th>
|
141 | <td>swipe right callback</td>
|
142 | </tr>
|
143 | <tr>
|
144 | <td>onSwipeTop</td>
|
145 | <td>function</td>
|
146 | <th></th>
|
147 | <td>swipe top callback</td>
|
148 | </tr>
|
149 | <tr>
|
150 | <td>onSwipeBottom</td>
|
151 | <td>function</td>
|
152 | <th></th>
|
153 | <td>swipe bottom callback</td>
|
154 | </tr>
|
155 | </tbody>
|
156 | </table>
|
157 |
|
158 | #### Pan
|
159 | <table class="table table-bordered table-striped">
|
160 | <thead>
|
161 | <tr>
|
162 | <th style="width: 100px;">name</th>
|
163 | <th style="width: 50px;">type</th>
|
164 | <th>default</th>
|
165 | <th>description</th>
|
166 | </tr>
|
167 | </thead>
|
168 | <tbody>
|
169 | <tr>
|
170 | <td>onPan</td>
|
171 | <td>function</td>
|
172 | <th></th>
|
173 | <td>pan callback, will triggered at the same time of all of below callback</td>
|
174 | </tr>
|
175 | <tr>
|
176 | <td>onPanStart</td>
|
177 | <td>function</td>
|
178 | <th></th>
|
179 | <td>drag start callback</td>
|
180 | </tr>
|
181 | <tr>
|
182 | <td>onPanMove</td>
|
183 | <td>function</td>
|
184 | <th></th>
|
185 | <td>drag move callback</td>
|
186 | </tr>
|
187 | <tr>
|
188 | <td>onPanEnd</td>
|
189 | <td>function</td>
|
190 | <th></th>
|
191 | <td>drag end callback</td>
|
192 | </tr>
|
193 | <tr>
|
194 | <td>onPanCancel</td>
|
195 | <td>function</td>
|
196 | <th></th>
|
197 | <td>drag cancel callback</td>
|
198 | </tr>
|
199 | <tr>
|
200 | <td>onPanLeft</td>
|
201 | <td>function</td>
|
202 | <th></th>
|
203 | <td>pan left callback</td>
|
204 | </tr>
|
205 | <tr>
|
206 | <td>onPanRight</td>
|
207 | <td>function</td>
|
208 | <th></th>
|
209 | <td>pan right callback</td>
|
210 | </tr>
|
211 | <tr>
|
212 | <td>onPanTop</td>
|
213 | <td>function</td>
|
214 | <th></th>
|
215 | <td>pan top callback</td>
|
216 | </tr>
|
217 | <tr>
|
218 | <td>onPanBottom</td>
|
219 | <td>function</td>
|
220 | <th></th>
|
221 | <td>pan bottom callback</td>
|
222 | </tr>
|
223 | </tbody>
|
224 | </table>
|
225 |
|
226 | #### Pinch
|
227 |
|
228 | pinch gesture is not enabled by default, you must set `props.enablePinch = true` at first;
|
229 |
|
230 | <table class="table table-bordered table-striped">
|
231 | <thead>
|
232 | <tr>
|
233 | <th style="width: 100px;">name</th>
|
234 | <th style="width: 50px;">type</th>
|
235 | <th>default</th>
|
236 | <th>description</th>
|
237 | </tr>
|
238 | </thead>
|
239 | <tbody>
|
240 | <tr>
|
241 | <td>onPinch</td>
|
242 | <td>function</td>
|
243 | <th></th>
|
244 | <td>pinch callback, will triggered at the same time of all of below callback</td>
|
245 | </tr>
|
246 | <tr>
|
247 | <td>onPinchStart</td>
|
248 | <td>function</td>
|
249 | <th></th>
|
250 | <td>pinch start callback</td>
|
251 | </tr>
|
252 | <tr>
|
253 | <td>onPinchMove</td>
|
254 | <td>function</td>
|
255 | <th></th>
|
256 | <td>pinch move callback</td>
|
257 | </tr>
|
258 | <tr>
|
259 | <td>onPinchEnd</td>
|
260 | <td>function</td>
|
261 | <th></th>
|
262 | <td>pinch end callback</td>
|
263 | </tr>
|
264 | <tr>
|
265 | <td>onPanCancel</td>
|
266 | <td>function</td>
|
267 | <th></th>
|
268 | <td>pinch cancel callback</td>
|
269 | </tr>
|
270 | <tr>
|
271 | <td>onPinchIn</td>
|
272 | <td>function</td>
|
273 | <th></th>
|
274 | <td>pinch in callback</td>
|
275 | </tr>
|
276 | <tr>
|
277 | <td>onPinchOut</td>
|
278 | <td>function</td>
|
279 | <th></th>
|
280 | <td>pinch out callback</td>
|
281 | </tr>
|
282 | </tbody>
|
283 | </table>
|
284 |
|
285 |
|
286 | #### Rotate
|
287 |
|
288 | pinch gesture is not enabled by default, you must set `props.enableRotate = true` at first;
|
289 |
|
290 | <table class="table table-bordered table-striped">
|
291 | <thead>
|
292 | <tr>
|
293 | <th style="width: 100px;">name</th>
|
294 | <th style="width: 50px;">type</th>
|
295 | <th>default</th>
|
296 | <th>description</th>
|
297 | </tr>
|
298 | </thead>
|
299 | <tbody>
|
300 | <tr>
|
301 | <td>onRotate</td>
|
302 | <td>function</td>
|
303 | <th></th>
|
304 | <td>rotate callback, will triggered at the same time of all of below callback</td>
|
305 | </tr>
|
306 | <tr>
|
307 | <td>onRotateStart</td>
|
308 | <td>function</td>
|
309 | <th></th>
|
310 | <td>rotate start callback</td>
|
311 | </tr>
|
312 | <tr>
|
313 | <td>onRotateMove</td>
|
314 | <td>function</td>
|
315 | <th></th>
|
316 | <td>rotate move callback</td>
|
317 | </tr>
|
318 | <tr>
|
319 | <td>onRotateEnd</td>
|
320 | <td>function</td>
|
321 | <th></th>
|
322 | <td>rotate end callback</td>
|
323 | </tr>
|
324 | <tr>
|
325 | <td>onRotateCancel</td>
|
326 | <td>function</td>
|
327 | <th></th>
|
328 | <td>rotate cancel callback</td>
|
329 | </tr>
|
330 | </tbody>
|
331 | </table>
|
332 |
|
333 | ## gesture
|
334 |
|
335 | ```tsx
|
336 | // http://hammerjs.github.io/api/#event-object
|
337 | export interface IGestureStauts {
|
338 | /* start status snapshot */
|
339 | startTime: number;
|
340 | startTouches: Finger[];
|
341 |
|
342 | startMutliFingerStatus?: MultiFingerStatus[];
|
343 |
|
344 | /* now status snapshot */
|
345 | time: number;
|
346 | touches: Finger[];
|
347 |
|
348 | mutliFingerStatus?: MultiFingerStatus[];
|
349 |
|
350 | /* delta status from touchstart to now, just for singe finger */
|
351 | moveStatus?: SingeFingerMoveStatus;
|
352 |
|
353 | /* whether is a long tap */
|
354 | press?: boolean;
|
355 |
|
356 | /* whether is a swipe*/
|
357 | swipe?: boolean;
|
358 | direction?: number;
|
359 |
|
360 | /* whether is in pinch process */
|
361 | pinch?: boolean;
|
362 | scale?: number;
|
363 |
|
364 | /* whether is in rotate process */
|
365 | rotate?: boolean;
|
366 | rotation?: number; // Rotation (in deg) that has been done when multi-touch. 0 on a single touch.
|
367 | };
|
368 | ```
|
369 |
|
370 | ## Development
|
371 |
|
372 | ```
|
373 | npm install
|
374 | npm start
|
375 | ```
|
376 |
|
377 | ## Example
|
378 |
|
379 | `npm start` and then go to `http://localhost:8005/examples/`
|
380 |
|
381 | Online examples: [http://react-component.github.io/gesture/](http://react-component.github.io/gesture/)
|
382 |
|
383 | ## Test Case
|
384 |
|
385 | `http://localhost:8005/tests/runner.html?coverage`
|
386 |
|
387 | ## Coverage
|
388 |
|
389 | `http://localhost:8005/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8088/tests/runner.html?coverage`
|
390 |
|
391 | ## License
|
392 |
|
393 | `rc-gesture` is released under the MIT license.
|