Skip to content

Fix for latest iPad scrolling instead of dragging vertically. #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 20 additions & 0 deletions lib/DraggableCore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let dragEventFor = eventsFor.mouse;

type CoreState = {
dragging: boolean,
scrolling: boolean,
lastX: number,
lastY: number,
touchIdentifier: ?number
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -253,6 +258,12 @@ export default class DraggableCore extends React.Component {

handleDrag: EventHandler<MouseEvent> = (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;
Expand Down Expand Up @@ -336,6 +347,11 @@ export default class DraggableCore extends React.Component {
return this.handleDragStop(e);
};

removeScroll: EventHandler<MouseEvent> = (e) => {
e.preventDefault();
return false;
};

// Same as onMouseDown (start drag), but now consider this a touch device.
onTouchStart: EventHandler<MouseEvent> = (e) => {
// We're on a touch device now, so change the event handlers
Expand All @@ -347,6 +363,10 @@ export default class DraggableCore extends React.Component {
onTouchEnd: EventHandler<MouseEvent> = (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);
};
Expand Down