feat: performance improvements

This commit is contained in:
2026-04-06 20:16:46 +02:00
parent d7e9788f99
commit 2994735f3b
4 changed files with 78 additions and 35 deletions

View File

@@ -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);