Prevent grid items from jumping after closing reader

Due to the reader and the "default" nav bar updating the same navbar width in the context, the grid item width calculation resulted in different grid item widths, which caused the items to "jump" after closing the reader
This commit is contained in:
schroda
2024-07-29 17:22:49 +02:00
parent b17fcd30af
commit b80622cb17
11 changed files with 54 additions and 39 deletions

View File

@@ -6,7 +6,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
@@ -73,7 +73,7 @@ const navbarItems: Array<NavbarItem> = [
];
export function DefaultNavBar() {
const { title, action, override, isCollapsed, setIsCollapsed, setAppBarHeight, navBarWidth } =
const { title, action, override, isCollapsed, setIsCollapsed, setAppBarHeight, navBarWidth, setNavBarWidth } =
useContext(NavBarContext);
const { pathname } = useLocation();
@@ -98,6 +98,15 @@ export function DefaultNavBar() {
);
const NavBarComponent = useMemo(() => (isMobileWidth ? MobileBottomBar : DesktopSideBar), [isMobileWidth]);
useLayoutEffect(() => {
if (!isMobileWidth) {
// do not reset navbar width to prevent grid from jumping due to the changing grid item width
return;
}
setNavBarWidth(0);
}, [isMobileWidth]);
const navBar = useMemo(
() => <NavBarComponent navBarItems={visibleNavBarItems} />,
[NavBarComponent, visibleNavBarItems],