Skip to content

Commit

Permalink
Fix for drag in scrolling container: set dropEffect to 'none' when ca…
Browse files Browse the repository at this point in the history
…nDrop is false (#1131)

* Set dropEffect to 'none' when canDrop is false. dropEffect should not depend on drag source rect (if drag source position has changed, dropEffect should be 'none' when drop is disabled).

* Remove unused code (we don't need to get/compare currentDragSourceNodeOffset anymore)

* revert lodash change
  • Loading branch information
eaglus authored and darthtrevino committed Nov 5, 2018
1 parent 87bf9c4 commit 7c255dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
3 changes: 1 addition & 2 deletions packages/react-dnd-html5-backend/package.json
Expand Up @@ -21,8 +21,7 @@
},
"dependencies": {
"dnd-core": "^4.0.5",
"lodash": "^4.17.11",
"shallowequal": "^1.1.0"
"lodash": "^4.17.11"
},
"devDependencies": {
"@types/react": "16.3.14",
Expand Down
32 changes: 2 additions & 30 deletions packages/react-dnd-html5-backend/src/HTML5Backend.ts
Expand Up @@ -6,7 +6,6 @@ import {
DragDropActions,
DragDropMonitor,
HandlerRegistry,
XYCoord,
} from 'dnd-core'
import EnterLeaveCounter from './EnterLeaveCounter'
import { isFirefox } from './BrowserDetector'
Expand All @@ -22,7 +21,6 @@ import {
import * as NativeTypes from './NativeTypes'
import { HTML5BackendContext } from './interfaces'
const defaults = require('lodash/defaults')
const shallowEqual = require('shallowequal')

declare global {
// tslint:disable-next-line interface-name
Expand Down Expand Up @@ -50,8 +48,6 @@ export default class HTML5Backend implements Backend {
private currentNativeSource: any = null
private currentNativeHandle: any = null
private currentDragSourceNode: any = null
private currentDragSourceNodeOffset: XYCoord | null = null
private currentDragSourceNodeOffsetChanged: boolean = false
private altKeyPressed: boolean = false
private mouseMoveTimeoutTimer: any = null
private asyncEndDragFrameId: any = null
Expand Down Expand Up @@ -279,8 +275,6 @@ export default class HTML5Backend implements Backend {
private setCurrentDragSourceNode(node: any) {
this.clearCurrentDragSourceNode()
this.currentDragSourceNode = node
this.currentDragSourceNodeOffset = getNodeClientOffset(node)
this.currentDragSourceNodeOffsetChanged = false

// A timeout of > 0 is necessary to resolve Firefox issue referenced
// See:
Expand Down Expand Up @@ -315,8 +309,6 @@ export default class HTML5Backend implements Backend {
private clearCurrentDragSourceNode() {
if (this.currentDragSourceNode) {
this.currentDragSourceNode = null
this.currentDragSourceNodeOffset = null
this.currentDragSourceNodeOffsetChanged = false

if (this.window) {
this.window.clearTimeout(this.mouseMoveTimeoutTimer)
Expand All @@ -334,24 +326,6 @@ export default class HTML5Backend implements Backend {
return false
}

private checkIfCurrentDragSourceRectChanged() {
const node = this.currentDragSourceNode
if (!node) {
return false
}

if (this.currentDragSourceNodeOffsetChanged) {
return true
}

this.currentDragSourceNodeOffsetChanged = !shallowEqual(
getNodeClientOffset(node),
this.currentDragSourceNodeOffset,
)

return this.currentDragSourceNodeOffsetChanged
}

private handleTopDragStartCapture = () => {
this.clearCurrentDragSourceNode()
this.dragStartSourceIds = []
Expand Down Expand Up @@ -570,11 +544,9 @@ export default class HTML5Backend implements Backend {
// "drop and blow away the whole document" action.
e.preventDefault()
e.dataTransfer.dropEffect = 'none'
} else if (this.checkIfCurrentDragSourceRectChanged()) {
// Prevent animating to incorrect position.
// Drop effect must be other than 'none' to prevent animation.
} else {
e.preventDefault()
e.dataTransfer.dropEffect = 'move'
e.dataTransfer.dropEffect = 'none'
}
}

Expand Down

0 comments on commit 7c255dc

Please sign in to comment.