diff --git a/lib/DraggableCore.es6 b/lib/DraggableCore.es6 index 1e630dd3..835aae61 100644 --- a/lib/DraggableCore.es6 +++ b/lib/DraggableCore.es6 @@ -28,6 +28,7 @@ let dragEventFor = eventsFor.mouse; type CoreState = { dragging: boolean, + scrolling: boolean, lastX: number, lastY: number, touchIdentifier: ?number @@ -174,6 +175,8 @@ export default class DraggableCore extends React.Component { state: CoreState = { dragging: false, + // Used in fix for ipad so we can keep up with when we've stopped scrolling. + scrolling: true, // Used while dragging to determine deltas. lastX: NaN, lastY: NaN, touchIdentifier: null @@ -187,6 +190,8 @@ export default class DraggableCore extends React.Component { removeEvent(ownerDocument, eventsFor.touch.move, this.handleDrag); removeEvent(ownerDocument, eventsFor.mouse.stop, this.handleDragStop); removeEvent(ownerDocument, eventsFor.touch.stop, this.handleDragStop); + removeEvent(ownerDocument, eventsFor.touch.move, this.removeScroll); + this.setState({scrolling: true}); if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument.body); } @@ -253,6 +258,12 @@ export default class DraggableCore extends React.Component { handleDrag: EventHandler = (e) => { + // Stop scrolling on touch devices while user is dragging as this is an issue for ipad. + if (this.state.dragging && this.state.scrolling) { + const {ownerDocument} = ReactDOM.findDOMNode(this); + addEvent(ownerDocument, eventsFor.touch.move, this.removeScroll); + this.setState({scrolling: false}) + } // Get the current drag point from the event. This is used as the offset. const position = getControlPosition(e, this.state.touchIdentifier, this); if (position == null) return; @@ -336,6 +347,11 @@ export default class DraggableCore extends React.Component { return this.handleDragStop(e); }; + removeScroll: EventHandler = (e) => { + e.preventDefault(); + return false; + }; + // Same as onMouseDown (start drag), but now consider this a touch device. onTouchStart: EventHandler = (e) => { // We're on a touch device now, so change the event handlers @@ -347,6 +363,10 @@ export default class DraggableCore extends React.Component { onTouchEnd: EventHandler = (e) => { // We're on a touch device now, so change the event handlers dragEventFor = eventsFor.touch; + // Remove the event listener that stopped document scrolling on touch devices + const {ownerDocument} = ReactDOM.findDOMNode(this); + removeEvent(ownerDocument, eventsFor.touch.move, this.removeScroll); + this.setState({scrolling: true}); return this.handleDragStop(e); };