Skip to content

Commit 3fc5126

Browse files
Fix forgotten requestAnimationFrame call (#773)
1 parent a61bd5f commit 3fc5126

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

lib/DraggableCore.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import ReactDOM from 'react-dom';
55
import {matchesSelectorAndParentsTo, addEvent, removeEvent, addUserSelectStyles, getTouchIdentifier,
6-
removeUserSelectStyles} from './utils/domFns';
6+
scheduleRemoveUserSelectStyles} from './utils/domFns';
77
import {createCoreData, getControlPosition, snapToGrid} from './utils/positionFns';
88
import {dontSetMe} from './utils/shims';
99
import log from './utils/log';
@@ -265,16 +265,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps> {
265265
removeEvent(ownerDocument, eventsFor.mouse.stop, this.handleDragStop);
266266
removeEvent(ownerDocument, eventsFor.touch.stop, this.handleDragStop);
267267
removeEvent(thisNode, eventsFor.touch.start, this.onTouchStart, {passive: false});
268-
if (this.props.enableUserSelectHack) {
269-
// prevent a possible "forced reflow"
270-
if (window.requestAnimationFrame) {
271-
window.requestAnimationFrame(() => {
272-
removeUserSelectStyles(ownerDocument);
273-
});
274-
} else {
275-
removeUserSelectStyles(ownerDocument);
276-
}
277-
}
268+
if (this.props.enableUserSelectHack) scheduleRemoveUserSelectStyles(ownerDocument);
278269
}
279270
}
280271

@@ -413,7 +404,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps> {
413404
const thisNode = this.findDOMNode();
414405
if (thisNode) {
415406
// Remove user-select hack
416-
if (this.props.enableUserSelectHack) removeUserSelectStyles(thisNode.ownerDocument);
407+
if (this.props.enableUserSelectHack) scheduleRemoveUserSelectStyles(thisNode.ownerDocument);
417408
}
418409

419410
log('DraggableCore: handleDragStop: %j', coreEvent);

lib/utils/domFns.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,18 @@ export function addUserSelectStyles(doc: ?Document) {
166166
if (doc.body) addClassName(doc.body, 'react-draggable-transparent-selection');
167167
}
168168

169-
export function removeUserSelectStyles(doc: ?Document) {
169+
export function scheduleRemoveUserSelectStyles(doc: ?Document) {
170+
// Prevent a possible "forced reflow"
171+
if (window.requestAnimationFrame) {
172+
window.requestAnimationFrame(() => {
173+
removeUserSelectStyles(doc);
174+
});
175+
} else {
176+
removeUserSelectStyles(doc);
177+
}
178+
}
179+
180+
function removeUserSelectStyles(doc: ?Document) {
170181
if (!doc) return;
171182
try {
172183
if (doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection');

0 commit comments

Comments
 (0)