Files
ohif-viewer/platform/ui/src/contextProviders/DragAndDropProvider.tsx
T

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-05-14 22:01:34 -04:00
import React from 'react';
2020-06-03 14:07:24 -04:00
import PropTypes from 'prop-types';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
2020-08-14 15:25:08 -03:00
// import TouchBackend from 'react-dnd-touch-backend';
2020-05-14 22:01:34 -04:00
2020-06-03 15:08:19 -04:00
// TODO: this is false when it should not be :thinking:
2020-06-03 14:07:24 -04:00
const isTouchDevice =
typeof window !== `undefined` &&
!!('ontouchstart' in window || navigator.maxTouchPoints);
2020-05-14 22:01:34 -04:00
/**
* Relevant:
* https://github.com/react-dnd/react-dnd/issues/186#issuecomment-335429067
* https://github.com/react-dnd/react-dnd/issues/186#issuecomment-282789420
*
* Docs:
* http://react-dnd.github.io/react-dnd/docs/api/drag-drop-context
*/
2020-06-03 14:07:24 -04:00
function DragAndDropProvider({ children }) {
2020-06-03 15:08:19 -04:00
const backend = HTML5Backend; // isTouchDevice ? TouchBackend : HTML5Backend;
const opts = {}; // isTouchDevice ? { enableMouseEvents: true } : {};
console.log('using... touch backend?', isTouchDevice);
2020-05-14 22:01:34 -04:00
return (
<DndProvider backend={backend} opts={opts}>
{children}
</DndProvider>
);
}
2020-06-03 14:07:24 -04:00
DragAndDropProvider.propTypes = {
children: PropTypes.any,
};
export default DragAndDropProvider;