Skip to content

Commit

Permalink
Delay drag padding rendering
Browse files Browse the repository at this point in the history
To fix chrome drag preview bug
  • Loading branch information
bor3ham committed Aug 25, 2021
1 parent 8c88539 commit 3cc4565
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions react-editor/src/components/draggable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ function useMouseCoords() {
return getCoords
}

function useDragDelay(currentDelay) {
const [delayed, setDelayed] = useState(currentDelay)
useEffect(() => {
const update = () => {
setDelayed(currentDelay)
}
const timed = window.setTimeout(update, 500)
return () => {
window.clearTimeout(timed)
}
}, [currentDelay])
return delayed
}

function Draggable(props) {
const getCoords = useMouseCoords()
const draggableRef = useRef()
Expand Down Expand Up @@ -124,6 +138,7 @@ function Draggable(props) {
}),
})
const deletable = typeof props.onDelete === 'function'
const delayedDragHappening = useDragDelay(isDragHappening)
return (
<>
<div
Expand All @@ -143,7 +158,7 @@ function Draggable(props) {
paddingBottom: isAfterActive ? activeHeight : 0,
}}
>
{!isBeingDragged && isDragHappening && (
{!isBeingDragged && delayedDragHappening && (
<div
className="drop-adjacent before"
ref={beforeDrop}
Expand All @@ -156,7 +171,7 @@ function Draggable(props) {
}}
/>
)}
{!isBeingDragged && isDragHappening && (
{!isBeingDragged && delayedDragHappening && (
<div
className="drop-adjacent after"
ref={afterDrop}
Expand Down

0 comments on commit 3cc4565

Please sign in to comment.