Skip to content

Commit 42bff01

Browse files
committed
Add animation frame.
1 parent ddac6c6 commit 42bff01

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/components/drops/drop/useMakeUpdatePosition.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,20 @@ export default (target, dropRef, align, stretch, canHideTarget, keepHorizontal)
7878
const width = getWidth(stretch, targetRect, dropRect)
7979
dropRect.width = width
8080

81-
const x = getXPosition(align, targetRect, dropRect, canHideTarget)
82-
const y = getYPosition(align, targetRect, dropRect, canHideTarget)
81+
const animate = () => {
82+
const x = getXPosition(align, targetRect, dropRect, canHideTarget)
83+
const y = getYPosition(align, targetRect, dropRect, canHideTarget)
8384

84-
if (!keepHorizontal || !dropRef.current.style.left) {
85-
dropRef.current.style.left = `${x}px`
86-
}
87-
dropRef.current.style.top = `${y}px`
88-
if (stretch) {
89-
dropRef.current.style.width = `${width}px`
85+
if (!dropRef.current) return
86+
87+
if (!keepHorizontal || !dropRef.current.style.left) {
88+
dropRef.current.style.left = `${x}px`
89+
}
90+
91+
dropRef.current.style.top = `${y}px`
92+
if (stretch) {
93+
dropRef.current.style.width = `${width}px`
94+
}
9095
}
96+
requestAnimationFrame(animate)
9197
}, [target, align, stretch])

0 commit comments

Comments
 (0)