Open
Description
1). Using the pattern below getOffset
is called before the preview portal is created, so the container is empty. I've worked around this by passing the element itself as the container.
2). Even so, on drop, the current position is randomly 1 pixel off the native rendered position, so the object seems to jump if it is absolutely positioned. (This doesn't happen if I disable the native drag preview via disableNativeDragPreview
).
onGenerateDragPreview: ({ nativeSetDragImage, location, source }) => {
setCustomNativeDragPreview({
render: ({ container }) => {
setPreview(container);
return () => setPreview(undefined);
},
getOffset: ({ container }) => {
// container is empty, so pass in source element.
const f = preserveOffsetOnSource({ element: source.element, input: location.current.input });
offset.current = f({ container: source.element });
return offset.current;
},
nativeSetDragImage,
});
...
return (
<>
{preview ? createPortal(<DragElement />, preview) : null}
<DragElement ref={draggingRef} classNames={[dragging && 'opacity-50']} />
</>
);
Metadata
Assignees
Labels
No labels
Activity