react-point
Version:
Fast touch events for React
2 lines (1 loc) • 4.15 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):t.ReactPoint=e(t.React)}(this,function(t){"use strict";function e(t){return function(){return t}}t=t&&t.hasOwnProperty("default")?t.default:t;var n=function(){};n.thatReturns=e,n.thatReturnsFalse=e(!1),n.thatReturnsTrue=e(!0),n.thatReturnsNull=e(null),n.thatReturnsThis=function(){return this},n.thatReturnsArgument=function(t){return t};var o=n,r=function(t,e,n,o,r,u,i,c){if(!t){var a;if(void 0===e)a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,o,r,u,i,c],h=0;(a=new Error(e.replace(/%s/g,function(){return s[h++]}))).name="Invariant Violation"}throw a.framesToPop=1,a}},u="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",i=function(){function t(t,e,n,o,i,c){c!==u&&r(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e};return n.checkPropTypes=o,n.PropTypes=n,n},c=(function(t,e){e={exports:{}},t(e,e.exports),e.exports}(function(t){t.exports=i()}),function(){function t(t){this.value=t}function e(e){function n(r,u){try{var i=e[r](u),c=i.value;c instanceof t?Promise.resolve(c.value).then(function(t){n("next",t)},function(t){n("throw",t)}):o(i.done?"return":"normal",i.value)}catch(t){o("throw",t)}}function o(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):u=null}var r,u;this._invoke=function(t,e){return new Promise(function(o,i){var c={key:t,arg:e,resolve:o,reject:i,next:null};u?u=u.next=c:(r=u=c,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),a=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},s=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},h=function(t){return t.touches[0].clientX},l=function(t){return t.touches[0].clientY},f=function(e){function n(){var t,o,r;c(this,n);for(var u=arguments.length,i=Array(u),a=0;a<u;a++)i[a]=arguments[a];return t=o=s(this,e.call.apply(e,[this].concat(i))),o.handleClick=function(){!o.usingTouch&&o.props.onPoint&&o.props.onPoint()},o.handleTouchStart=function(t){o.usingTouch=!0,o.touchStarted||(o.touchStarted=!0,o.touchMoved=!1,o.startX=h(t),o.startY=l(t))},o.handleTouchMove=function(t){if(!o.touchMoved){var e=o.props.tolerance;o.touchMoved=Math.abs(o.startX-h(t))>e||Math.abs(o.startY-l(t))>e}},o.handleTouchCancel=function(){o.touchStarted=o.touchMoved=!1,o.startX=o.startY=0},o.handleTouchEnd=function(){o.touchStarted=!1,!o.touchMoved&&o.props.onPoint&&o.props.onPoint()},r=t,s(o,r)}return a(n,e),n.prototype.componentWillMount=function(){this.usingTouch=!1},n.prototype.render=function(){var e=this.props.children,n=e?t.Children.only(e):t.createElement("button",null);return t.cloneElement(n,{onClick:this.handleClick,onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchCancel:this.handleTouchCancel,onTouchEnd:this.handleTouchEnd})},n}(t.Component);return f.defaultProps={tolerance:10},f});