Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-touch",
"version": "0.0.6",
"description": "React component library for building inertial touch applications.",
"main": "lib/ReactTouch.js",
"main": "src/ReactTouch.js",
"peerDependencies": {
"react": "~0.9"
},
Expand Down
4 changes: 1 addition & 3 deletions src/ReactTouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ var Router = require('./routing/Router');
var ReactTouch = {
start: function(componentClass, domNode, routes, useHistory) {
var EventPluginHub = require('react/lib/EventPluginHub');
var ResponderEventPlugin = require('./thirdparty/ResponderEventPlugin');
var TapEventPlugin = require('./thirdparty/TapEventPlugin');

EventPluginHub.injection.injectEventPluginsByName({
ResponderEventPlugin: ResponderEventPlugin,
TapEventPlugin: TapEventPlugin
});

Expand All @@ -19,4 +17,4 @@ var ReactTouch = {
}
};

module.exports = ReactTouch;
module.exports = ReactTouch;
38 changes: 38 additions & 0 deletions src/primitives/TouchableArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@ var TouchableArea = React.createClass({
};
},

handleMouseStart: function(e) {
if (!this.props.scroller || !this.props.touchable) {
return;
}

// TODO: what’s the best way to handle this with React?
// The problem is if your mouse gets away from the target element it will
// no longer receive the mousemove or mouseup events so we need to capture
// these events at the document level.
document.body.addEventListener('mousemove', this.handleMouseMove, false);
document.body.addEventListener('mouseup', this.handleMouseEnd, false);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit right here is namely where my concern is. I suspect that the ResponderEventsPlugin may be what I need to keep mousemove events focused on initial target to match the implementation of touchmove events. Is this correct?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointerevents follow the mouse rules by default, but expose two additional methods to opt-in and out of the touch model at will.

  • setPointerCapture
  • releasePointerCapture

To see what this looks like in action check out: http://patrickhlauke.github.io/touch/tests/pointercapture.html

Spec: http://www.w3.org/TR/pointerevents/#attributes-2
MSDN Docs: http://msdn.microsoft.com/en-us/library/ie/hh771882%28v=vs.85%29.aspx


this.props.scroller.doTouchStart([e], e.timeStamp);
e.preventDefault();
},

handleMouseMove: function(e) {
if (!this.props.scroller || !this.props.touchable) {
return;
}

this.props.scroller.doTouchMove([e], e.timeStamp);
e.preventDefault();
},

handleMouseEnd: function(e) {
if (!this.props.scroller || !this.props.touchable) {
return;
}

document.body.removeEventListener('mousemove', this.handleMouseMove);
document.body.removeEventListener('mouseup', this.handleMouseEnd);

this.props.scroller.doTouchEnd(e.timeStamp);
e.preventDefault();
},

handleTouchStart: function(e) {
if (!this.props.scroller || !this.props.touchable) {
return;
Expand Down Expand Up @@ -41,6 +78,7 @@ var TouchableArea = React.createClass({
var component = this.props.component;
return this.transferPropsTo(
<component
onMouseDown={this.handleMouseStart}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does react handle this gracefully if the component already has onMouseDown or other events bound to it or is it a last-in wins scenario?

onTouchStart={this.handleTouchStart}
onTouchMove={this.handleTouchMove}
onTouchEnd={this.handleTouchEnd}
Expand Down