react-hammerjs
Version:
ReactJS / HammerJS integration. Support touch events in your React app.
2 lines (1 loc) • 3.46 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["prop-types","react"],t):e.Hammer=t(e.PropTypes,e.React)}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){t.hasOwnProperty("vertical")&&console.warn("vertical is deprecated, please use `direction` instead");var n=t.direction;if(n||t.hasOwnProperty("vertical")){var o=n||(t.vertical?"DIRECTION_ALL":"DIRECTION_HORIZONTAL");e.get("pan").set({direction:c[o]}),e.get("swipe").set({direction:c[o]})}t.options&&Object.keys(t.options).forEach(function(n){if("recognizers"===n)Object.keys(t.options.recognizers).forEach(function(n){var o=e.get(n);o.set(t.options.recognizers[n]),t.options.recognizers[n].requireFailure&&o.requireFailure(t.options.recognizers[n].requireFailure)},this);else{var o={};o[n]=t.options[n],e.set(o)}},this),t.recognizeWith&&Object.keys(t.recognizeWith).forEach(function(n){e.get(n).recognizeWith(t.recognizeWith[n])},this),Object.keys(t).forEach(function(n){var o=p[n];o&&(e.off(o),e.on(o,t[n]))})}e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t;var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),c="undefined"!=typeof window?require("hammerjs"):void 0,s={children:!0,direction:!0,options:!0,recognizeWith:!0,vertical:!0},p={action:"tap press",onDoubleTap:"doubletap",onPan:"pan",onPanCancel:"pancancel",onPanEnd:"panend",onPanStart:"panstart",onPinch:"pinch",onPinchCancel:"pinchcancel",onPinchEnd:"pinchend",onPinchIn:"pinchin",onPinchOut:"pinchout",onPinchStart:"pinchstart",onPress:"press",onPressUp:"pressup",onRotate:"rotate",onRotateCancel:"rotatecancel",onRotateEnd:"rotateend",onRotateMove:"rotatemove",onRotateStart:"rotatestart",onSwipe:"swipe",onSwipeRight:"swiperight",onSwipeLeft:"swipeleft",onSwipeUp:"swipeup",onSwipeDown:"swipedown",onTap:"tap"};Object.keys(p).forEach(function(e){s[e]=!0});var u=function(e){function p(){return n(this,p),o(this,(p.__proto__||Object.getPrototypeOf(p)).apply(this,arguments))}return r(p,t.Component),a(p,[{key:"componentDidMount",value:function(){this.hammer=new c(this.domElement),i(this.hammer,this.props)}},{key:"componentDidUpdate",value:function(){this.hammer&&i(this.hammer,this.props)}},{key:"componentWillUnmount",value:function(){this.hammer&&(this.hammer.stop(),this.hammer.destroy()),this.hammer=null}},{key:"render",value:function(){var e={};Object.keys(this.props).forEach(function(t){s[t]||(e[t]=this.props[t])},this);var n=this;return e.ref=function(e){n.props.ref&&n.props.ref(e),n.domElement=e},t.cloneElement(t.Children.only(this.props.children),e)}}]),p}();return u.displayName="Hammer",u});