fix: stop layout wobble when the window is resized
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
- drop the global transition:all on .scrollY/.library-items (it animated width/height during every resize) - library grid reacts to width changes only, coalesced in rAF, and measures offsetTop after the new columns are applied - header transitions no longer animate layout properties - disable transitions for 200ms while the OS window is being resized
This commit is contained in:
1 parent
fa29331c1c
commit
08f0ca0df1
4 files changed
+53
-29
No files matched your search
@@ -10,7 +10,7 @@
|
||||
width: calc(100vw - 4em) !important;
|
||||
z-index: 10;
|
||||
padding: 0.25em !important;
|
||||
transition: all 0.2s ease-in-out;
|
||||
transition: background-color 0.2s ease-in-out, opacity 0.2s ease-in-out;
|
||||
|
||||
html.is-macos & {
|
||||
// The window has an overlay titlebar: keep controls clear of the traffic lights
|
||||
|
||||
@@ -173,32 +173,42 @@ const LibraryItemsGrid = () => {
|
||||
const [containerWidth, setContainerWidth] = useState<number>(0);
|
||||
const [scrollMargin, setScrollMargin] = useState<number>(0);
|
||||
|
||||
// Determine column count based on container width (simple heuristic)
|
||||
// Determine column count based on container width (simple heuristic).
|
||||
// Only width changes matter: observing height caused re-layout feedback while
|
||||
// the window was resized, and a transitioned header made rows jump.
|
||||
const [columns, setColumns] = useState(1);
|
||||
const measureColumns = useCallback(() => {
|
||||
if (!parentRef.current) return;
|
||||
const width = parentRef.current.clientWidth;
|
||||
setContainerWidth(width);
|
||||
setScrollMargin(parentRef.current.offsetTop);
|
||||
// Base desired approximate card width (including gap) 180px
|
||||
const ideal = Math.max(1, Math.floor(width / 180));
|
||||
setColumns(ideal);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
measureColumns();
|
||||
if (!parentRef.current) return;
|
||||
const element = parentRef.current;
|
||||
if (!element) return;
|
||||
let frame = 0;
|
||||
let lastWidth = -1;
|
||||
|
||||
const ro = new ResizeObserver(() => measureColumns());
|
||||
ro.observe(parentRef.current);
|
||||
// The audio player and headers can change the page layout; a resize
|
||||
// listener is enough (observing <body> fires on every image load).
|
||||
window.addEventListener("resize", measureColumns);
|
||||
return () => {
|
||||
ro.disconnect();
|
||||
window.removeEventListener("resize", measureColumns);
|
||||
const measure = () => {
|
||||
frame = 0;
|
||||
const width = element.clientWidth;
|
||||
if (Math.abs(width - lastWidth) < 1) return;
|
||||
lastWidth = width;
|
||||
setContainerWidth(width);
|
||||
setColumns(Math.max(1, Math.floor(width / 180)));
|
||||
// Read offsetTop after the browser has applied the new columns.
|
||||
frame = requestAnimationFrame(() => {
|
||||
frame = 0;
|
||||
setScrollMargin(element.offsetTop);
|
||||
});
|
||||
};
|
||||
}, [measureColumns]);
|
||||
|
||||
const schedule = () => {
|
||||
if (!frame) frame = requestAnimationFrame(measure);
|
||||
};
|
||||
|
||||
schedule();
|
||||
const observer = new ResizeObserver(schedule);
|
||||
observer.observe(element);
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
if (frame) cancelAnimationFrame(frame);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const itemCount = items.data?.Items?.length ?? 0;
|
||||
// Compute number of virtual rows
|
||||
|
||||
@@ -100,6 +100,17 @@ const init = async () => {
|
||||
document.documentElement.classList.add("is-macos");
|
||||
}
|
||||
|
||||
// Layout transitions during a live window resize cause visible wobble
|
||||
// (headers, cards, MUI components). Disable them until resizing settles.
|
||||
let resizeTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
window.addEventListener("resize", () => {
|
||||
document.documentElement.classList.add("is-resizing");
|
||||
if (resizeTimer) clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(() => {
|
||||
document.documentElement.classList.remove("is-resizing");
|
||||
}, 200);
|
||||
});
|
||||
|
||||
const initialApi = await initializeApi();
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
|
||||
@@ -36,13 +36,21 @@ html {
|
||||
overscroll-behavior: none;
|
||||
}
|
||||
|
||||
// While the OS window is being resized, skip layout transitions so elements
|
||||
// do not chase the new size frame by frame.
|
||||
html.is-resizing *,
|
||||
html.is-resizing *::before,
|
||||
html.is-resizing *::after {
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Plus Jakarta Sans Variable",system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||
background: $clr-background-default;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: relative;
|
||||
width: 100vw;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
@@ -205,11 +213,6 @@ h1 {
|
||||
padding-bottom: 9em !important;
|
||||
}
|
||||
|
||||
.library-items,
|
||||
.scrollY {
|
||||
transition: all $transition-time-default !important;
|
||||
}
|
||||
|
||||
// Normalize listItemIcons for material symbols
|
||||
.MuiListItemIcon-root {
|
||||
font-size: 24px;
|
||||
|
||||
Reference in new issue
Block a user