Skip to content

Instantly share code, notes, and snippets.

@shaunol
Created July 1, 2014 08:40
Show Gist options
  • Save shaunol/d1beef1f7e196f9c7b30 to your computer and use it in GitHub Desktop.
Save shaunol/d1beef1f7e196f9c7b30 to your computer and use it in GitHub Desktop.
/**
* @jsx React.DOM
*/
var React = require('react');
var TapEventMixin = {
Tap_onTouchStart: function(event) {
this.hasTouch = true;
var target = event.target,
touchStart = event.touches[0];
this.touchStartX = touchStart.pageX;
this.touchStartY = touchStart.pageY;
// Remove the tap and move handlers if the timeout expires
this.isTouched = true;
this.touchTimeout = setTimeout(this.Tap_touchInvalidated, 500);
},
Tap_onTouchMove: function(event) {
var touchMove = event.touches[0],
moveX = touchMove.pageX,
moveY = touchMove.pageY;
if (Math.abs(moveX - this.touchStartX) > 10 || Math.abs(moveY - this.touchStartY) > 10) {
this.Tap_touchInvalidated();
}
},
Tap_onTouchEnd: function(event) {
if(!this.isTouched) return;
this.Tap_touchInvalidated();
arguments[0].apply(this, Array.prototype.slice.call(arguments).slice(1));
},
Tap_onClick: function() {
if(this.hasTouch) return;
arguments[0].apply(this, Array.prototype.slice.call(arguments).slice(1));
},
Tap_touchInvalidated: function() {
this.isTouched = false;
clearTimeout(this.touchTimeout);
}
};
module.exports = TapEventMixin;
@shaunol
Copy link
Author

shaunol commented Jul 1, 2014

<span
    onTouchStart={this.Tap_onTouchStart} 
    onTouchMove={this.Tap_onTouchMove} 
    onTouchEnd={this.Tap_onTouchEnd.bind(this, this.selectTab, TabConstants.TAB_SUMMARY)} 
    onClick={this.Tap_onClick.bind(this, this.selectTab, TabConstants.TAB_SUMMARY)}>
        Summary
</span>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment