Merge remote-tracking branch 'origin/main' into feature/negodata
This commit is contained in:
commit
aed8364b40
12 files changed
+397
-44
No files matched your search
@@ -6,6 +6,7 @@ import { useEffect } from 'react';
|
||||
// 중첩 오버레이 대비 카운터로 관리 — 마지막 하나가 닫힐 때만 원복.
|
||||
let lockCount = 0;
|
||||
let prevOverflow = '';
|
||||
let pendingRestore = 0; // requestAnimationFrame id (0 = 없음)
|
||||
|
||||
function scroller(): HTMLElement {
|
||||
return (document.scrollingElement as HTMLElement | null) ?? document.documentElement;
|
||||
@@ -14,7 +15,13 @@ function scroller(): HTMLElement {
|
||||
export function useScrollLock(active = true) {
|
||||
useEffect(() => {
|
||||
if (!active) return;
|
||||
if (lockCount === 0) {
|
||||
if (pendingRestore !== 0) {
|
||||
// 직전 해제로 예약된 복원이 남아 있으면 취소 — 언마운트→재마운트(라운드 전환 등) 사이의
|
||||
// 일시적 0 을 흡수한다. 이때 overflow 는 아직 'hidden' 이고 prevOverflow 도 원래 값 그대로다.
|
||||
cancelAnimationFrame(pendingRestore);
|
||||
pendingRestore = 0;
|
||||
} else if (lockCount === 0) {
|
||||
// 진짜 첫 잠금일 때만 원래 overflow 를 보관하고 잠근다('hidden' 을 prevOverflow 로 캡처하는 사고 방지).
|
||||
const el = scroller();
|
||||
prevOverflow = el.style.overflow;
|
||||
el.style.overflow = 'hidden';
|
||||
@@ -23,7 +30,11 @@ export function useScrollLock(active = true) {
|
||||
return () => {
|
||||
lockCount -= 1;
|
||||
if (lockCount === 0) {
|
||||
scroller().style.overflow = prevOverflow;
|
||||
// 마지막 해제는 다음 프레임으로 미룬다 — 곧바로 새 잠금이 들어오면(재마운트) 위에서 취소된다.
|
||||
pendingRestore = requestAnimationFrame(() => {
|
||||
pendingRestore = 0;
|
||||
if (lockCount === 0) scroller().style.overflow = prevOverflow;
|
||||
});
|
||||
}
|
||||
};
|
||||
}, [active]);
|
||||
|
||||
Reference in new issue
Block a user