Skip to content

Commit

Permalink
feat: listen to mobile dnd events (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Jan 31, 2022
1 parent dc8e4eb commit f794e53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ export const DragAndDropProvider: React.FC = props => {

useEffect(() => {
window.addEventListener('dragend', onDropHandler);
return () => window.removeEventListener('dragend', onDropHandler);
window.addEventListener('touchend', onDropHandler);
return () => {
window.removeEventListener('dragend', onDropHandler);
window.removeEventListener('touchend', onDropHandler);
};
}, [onDropHandler]);

return <DragAndDropContext.Provider value={dnd}>{props.children}</DragAndDropContext.Provider>;
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tree/TreeManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const TreeManager = (): JSX.Element => {
const containerProps: HTMLProps<any> = {
// onDragOver: createOnDragOverHandler(environment, containerRef, lastHoverCode, getLinearItems, rootItem, treeId),
onDragOver: e => dnd.onDragOverTreeHandler(e as any, treeId, containerRef),
onMouseDown: () => dnd.abortProgrammaticDrag(),
onTouchMove: e => dnd.onDragOverTreeHandler(e as any, treeId, containerRef),
onMouseDown: dnd.abortProgrammaticDrag,
onTouchCancel: dnd.abortProgrammaticDrag,
ref: containerRef,
style: { position: 'relative' },
role: 'tree',
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/treeItem/useTreeItemRenderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ export const useTreeItemRenderContext = (item?: TreeItem) => {
canDropOn,
};

const interactiveProps = interactionManager.createInteractiveElementProps(item, treeId, actions, renderFlags);

const interactiveElementProps: HTMLProps<HTMLElement> = {
...interactionManager.createInteractiveElementProps(item, treeId, actions, renderFlags),
...interactiveProps,
onTouchStart: interactiveProps.onDragStart,
...({
['data-rct-item-interactive']: true,
['data-rct-item-focus']: renderFlags.isFocused ? 'true' : 'false',
Expand Down

0 comments on commit f794e53

Please sign in to comment.