Skip to content
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

fix: Need to drag draggable twice in mobile when using clones #2281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 9 additions & 9 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"dist/react-beautiful-dnd.js": {
"bundled": 364998,
"minified": 133574,
"gzipped": 39437
"bundled": 365551,
"minified": 133810,
"gzipped": 39559
},
"dist/react-beautiful-dnd.min.js": {
"bundled": 306810,
"minified": 108365,
"gzipped": 31340
"bundled": 307297,
"minified": 108548,
"gzipped": 31422
},
"dist/react-beautiful-dnd.esm.js": {
"bundled": 240910,
"minified": 125371,
"gzipped": 32650,
"bundled": 241424,
"minified": 125681,
"gzipped": 32722,
"treeshaked": {
"rollup": {
"code": 21121,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function getSelector(contextId: ContextId): string {
return `[${attributes.dragHandle.contextId}="${contextId}"]`;
}

function findClosestDragHandleFromEvent(
export function findClosestDragHandleFromEvent(
contextId: ContextId,
event: Event,
): ?HTMLElement {
Expand Down
17 changes: 12 additions & 5 deletions src/view/use-sensor-marshal/sensors/use-touch-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,14 @@ export default function useTouchSensor(api: SensorAPI) {
y: clientY,
};

const handle: ?HTMLElement = api.findClosestDragHandle(event);
invariant(handle, 'Touch sensor unable to find drag handle');

// unbind this event handler
unbindEventsRef.current();

// eslint-disable-next-line no-use-before-define
startPendingDrag(actions, point);
startPendingDrag(actions, point, handle);
},
}),
// not including stop or startPendingDrag as it is not defined initially
Expand Down Expand Up @@ -350,7 +353,7 @@ export default function useTouchSensor(api: SensorAPI) {
}, [stop]);

const bindCapturingEvents = useCallback(
function bindCapturingEvents() {
function bindCapturingEvents(target: HTMLElement) {
const options: EventOptions = { capture: true, passive: false };
const args: GetBindingArgs = {
cancel,
Expand All @@ -366,7 +369,7 @@ export default function useTouchSensor(api: SensorAPI) {
// Old behaviour:
// https://gist.github.com/parris/dda613e3ae78f14eb2dc9fa0f4bfce3d
// https://stackoverflow.com/questions/33298828/touch-move-event-dont-fire-after-touch-start-target-is-removed
const unbindTarget = bindEvents(window, getHandleBindings(args), options);
const unbindTarget = bindEvents(target, getHandleBindings(args), options);
const unbindWindow = bindEvents(window, getWindowBindings(args), options);

unbindEventsRef.current = function unbindAll() {
Expand Down Expand Up @@ -397,7 +400,11 @@ export default function useTouchSensor(api: SensorAPI) {
);

const startPendingDrag = useCallback(
function startPendingDrag(actions: PreDragActions, point: Position) {
function startPendingDrag(
actions: PreDragActions,
point: Position,
target: HTMLElement,
) {
invariant(
getPhase().type === 'IDLE',
'Expected to move from IDLE to PENDING drag',
Expand All @@ -415,7 +422,7 @@ export default function useTouchSensor(api: SensorAPI) {
longPressTimerId,
});

bindCapturingEvents();
bindCapturingEvents(target);
},
[bindCapturingEvents, getPhase, setPhase, startDragging],
);
Expand Down
12 changes: 11 additions & 1 deletion src/view/use-sensor-marshal/use-sensor-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import getBorderBoxCenterPosition from '../get-border-box-center-position';
import { warning } from '../../dev-warning';
import useLayoutEffect from '../use-isomorphic-layout-effect';
import { noop } from '../../empty';
import findClosestDraggableIdFromEvent from './find-closest-draggable-id-from-event';
import findClosestDraggableIdFromEvent, {
findClosestDragHandleFromEvent,
} from './find-closest-draggable-id-from-event';
import findDraggable from '../get-elements/find-draggable';
import bindEvents from '../event-bindings/bind-events';

Expand Down Expand Up @@ -438,6 +440,12 @@ export default function useSensorMarshal({
[contextId, lockAPI, registry, store],
);

const findClosestDragHandle = useCallback(
(event: Event): ?DraggableId =>
findClosestDragHandleFromEvent(contextId, event),
[contextId],
);

const findClosestDraggableId = useCallback(
(event: Event): ?DraggableId =>
findClosestDraggableIdFromEvent(contextId, event),
Expand Down Expand Up @@ -473,6 +481,7 @@ export default function useSensorMarshal({
canGetLock,
tryGetLock,
findClosestDraggableId,
findClosestDragHandle,
findOptionsForDraggable,
tryReleaseLock,
isLockClaimed,
Expand All @@ -481,6 +490,7 @@ export default function useSensorMarshal({
canGetLock,
tryGetLock,
findClosestDraggableId,
findClosestDragHandle,
findOptionsForDraggable,
tryReleaseLock,
isLockClaimed,
Expand Down