feat: performance improvements
This commit is contained in:
@@ -91,12 +91,22 @@ export default function FloatingWindow({
|
||||
let curVx = vx;
|
||||
let curVy = vy;
|
||||
const friction = 0.92;
|
||||
const el = ref.current;
|
||||
const tick = () => {
|
||||
curVx *= friction;
|
||||
curVy *= friction;
|
||||
if (Math.abs(curVx) < 0.3 && Math.abs(curVy) < 0.3) { inertiaRef.current = 0; return; }
|
||||
if (Math.abs(curVx) < 0.3 && Math.abs(curVy) < 0.3) {
|
||||
inertiaRef.current = 0;
|
||||
// Sync final position to React state once
|
||||
onUpdate(id, posRef.current);
|
||||
return;
|
||||
}
|
||||
posRef.current = { x: posRef.current.x + curVx, y: Math.max(0, posRef.current.y + curVy) };
|
||||
onUpdate(id, posRef.current);
|
||||
// Direct DOM update during animation — skip React reconciliation
|
||||
if (el) {
|
||||
el.style.left = `${posRef.current.x}px`;
|
||||
el.style.top = `${posRef.current.y}px`;
|
||||
}
|
||||
inertiaRef.current = requestAnimationFrame(tick);
|
||||
};
|
||||
inertiaRef.current = requestAnimationFrame(tick);
|
||||
|
||||
Reference in New Issue
Block a user