A local-first personal finance app
Hide mobile nav tabs on scroll (#1745)
Joel Jeremy Marquez0af2987cefdb
diff --git a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-1-chromium-linux.png b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-1-chromium-linux.pngindex dd2abcee93..66afa1a786 100644Binary files a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-1-chromium-linux.png and b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-2-chromium-linux.png b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-2-chromium-linux.pngindex 443581d98f..e50ea3fe2f 100644Binary files a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-2-chromium-linux.png and b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-checks-that-settings-page-can-be-opened-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.pngindex 465ea69cb5..a29cc002d9 100644Binary files a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png and b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-opens-the-accounts-page-and-asserts-on-balances-1-chromium-linux.png b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-opens-the-accounts-page-and-asserts-on-balances-1-chromium-linux.pngindex 900a67f119..43a9bdd4c2 100644Binary files a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-opens-the-accounts-page-and-asserts-on-balances-1-chromium-linux.png and b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-opens-the-accounts-page-and-asserts-on-balances-1-chromium-linux.png differdiff --git a/packages/desktop-client/src/components/FinancesApp.tsx b/packages/desktop-client/src/components/FinancesApp.tsxindex 92711dceaa..58792c219c 100644--- a/packages/desktop-client/src/components/FinancesApp.tsx+++ b/packages/desktop-client/src/components/FinancesApp.tsx@@ -5,7 +5,7 @@ import {Route,Routes,Navigate,- NavLink,+ useNavigate,BrowserRouter,useLocation,useHref,@@ -20,13 +20,8 @@ import checkForUpdateNotification from 'loot-core/src/client/update-notificationimport * as undo from 'loot-core/src/platform/client/undo';import { useActions } from '../hooks/useActions';-import useNavigate from '../hooks/useNavigate';-import Add from '../icons/v1/Add';-import Cog from '../icons/v1/Cog';-import PiggyBank from '../icons/v1/PiggyBank';-import Wallet from '../icons/v1/Wallet';import { useResponsive } from '../ResponsiveProvider';-import { theme, styles } from '../style';+import { theme } from '../style';import { ExposeNavigate } from '../util/router-tools';import { getIsOutdated, getLatestVersion } from '../util/versions';@@ -35,11 +30,13 @@ import { BudgetMonthCountProvider } from './budget/BudgetMonthCountContext';import View from './common/View';import GlobalKeys from './GlobalKeys';import { ManageRulesPage } from './ManageRulesPage';+import MobileNavTabs from './mobile/MobileNavTabs';import Modals from './Modals';import Notifications from './Notifications';import { ManagePayeesPage } from './payees/ManagePayeesPage';import Reports from './reports';import { NarrowAlternate, WideComponent } from './responsive';+import ScrollProvider from './ScrollProvider';import Settings from './settings';import FloatableSidebar, { SidebarProvider } from './sidebar';import Titlebar, { TitlebarProvider } from './Titlebar';@@ -73,48 +70,6 @@ function WideNotSupported({ children, redirectTo = '/budget' }) {return isNarrowWidth ? children : null;}-function NavTab({ icon: TabIcon, name, path }) {- return (- <NavLink- to={path}- style={({ isActive }) => ({- alignItems: 'center',- color: isActive ? theme.mobileNavItemSelected : theme.mobileNavItem,- display: 'flex',- flexDirection: 'column',- textDecoration: 'none',- })}- >- <TabIcon width={22} height={22} style={{ marginBottom: '5px' }} />- {name}- </NavLink>- );-}--function MobileNavTabs() {- const { isNarrowWidth } = useResponsive();- return (- <div- style={{- backgroundColor: theme.mobileNavBackground,- borderTop: `1px solid ${theme.menuBorder}`,- bottom: 0,- ...styles.shadow,- display: isNarrowWidth ? 'flex' : 'none',- height: '80px',- justifyContent: 'space-around',- paddingTop: 10,- width: '100%',- }}- >- <NavTab name="Budget" path="/budget" icon={Wallet} />- <NavTab name="Accounts" path="/accounts" icon={PiggyBank} />- <NavTab name="Transaction" path="/transactions/new" icon={Add} />- <NavTab name="Settings" path="/settings" icon={Cog} />- </div>- );-}-function RouterBehaviors({ getAccounts }) {let navigate = useNavigate();useEffect(() => {@@ -305,7 +260,9 @@ export default function FinancesAppWithContext() {<BudgetMonthCountProvider><PayeesProvider><AccountsProvider>- <DndProvider backend={Backend}>{app}</DndProvider>+ <DndProvider backend={Backend}>+ <ScrollProvider>{app}</ScrollProvider>+ </DndProvider></AccountsProvider></PayeesProvider></BudgetMonthCountProvider>diff --git a/packages/desktop-client/src/components/ScrollProvider.tsx b/packages/desktop-client/src/components/ScrollProvider.tsxnew file mode 100644index 0000000000..06e59fb60e--- /dev/null+++ b/packages/desktop-client/src/components/ScrollProvider.tsx@@ -0,0 +1,54 @@+import React, {+ type ReactNode,+ createContext,+ useState,+ useContext,+ useEffect,+} from 'react';++import debounce from 'debounce';++type IScrollContext = {+ scrollY: number | undefined;+ isBottomReached: boolean;+};++const ScrollContext = createContext<IScrollContext | undefined>(undefined);++type ScrollProviderProps = {+ children?: ReactNode;+};++export default function ScrollProvider({ children }: ScrollProviderProps) {+ const [scrollY, setScrollY] = useState(undefined);+ const [isBottomReached, setIsBottomReached] = useState(false);++ useEffect(() => {+ const listenToScroll = debounce(e => {+ setScrollY(e.target?.scrollTop || 0);+ setIsBottomReached(+ e.target?.scrollHeight - e.target?.scrollTop <= e.target?.clientHeight,+ );+ }, 20);++ window.addEventListener('scroll', listenToScroll, {+ capture: true,+ passive: true,+ });+ return () =>+ window.removeEventListener('scroll', listenToScroll, {+ capture: true,+ });+ }, []);++ return (+ <ScrollContext.Provider+ value={{ scrollY, isBottomReached }}+ children={children}+ />+ );+}++export function useScroll(): IScrollContext {+ return useContext(ScrollContext);+}diff --git a/packages/desktop-client/src/components/mobile/MobileNavTabs.tsx b/packages/desktop-client/src/components/mobile/MobileNavTabs.tsxnew file mode 100644index 0000000000..afa3c89b73--- /dev/null+++ b/packages/desktop-client/src/components/mobile/MobileNavTabs.tsx@@ -0,0 +1,82 @@+import React, { type ComponentType, useMemo } from 'react';+import { NavLink } from 'react-router-dom';++import usePrevious from '../../hooks/usePrevious';+import Add from '../../icons/v1/Add';+import Cog from '../../icons/v1/Cog';+import PiggyBank from '../../icons/v1/PiggyBank';+import Wallet from '../../icons/v1/Wallet';+import { useResponsive } from '../../ResponsiveProvider';+import { theme, styles } from '../../style';+import { useScroll } from '../ScrollProvider';++const height = 70;++export default function MobileNavTabs() {+ const { isNarrowWidth } = useResponsive();+ const { scrollY, isBottomReached } = useScroll();+ const previousScrollY = usePrevious(scrollY);++ const isVisible = useMemo(+ () =>+ previousScrollY === undefined ||+ (!isBottomReached && previousScrollY > scrollY) ||+ previousScrollY < 0,+ [scrollY],+ );++ return (+ <div+ style={{+ backgroundColor: theme.mobileNavBackground,+ borderTop: `1px solid ${theme.menuBorder}`,+ ...styles.shadow,+ display: isNarrowWidth ? 'flex' : 'none',+ height,+ justifyContent: 'space-around',+ paddingTop: 10,+ paddingBottom: 10,+ width: '100%',+ position: 'fixed',+ zIndex: 100,+ bottom: isVisible ? 0 : -height,+ transition: 'bottom 0.2s ease-out',+ }}+ >+ <NavTab name="Budget" path="/budget" icon={Wallet} />+ <NavTab name="Accounts" path="/accounts" icon={PiggyBank} />+ <NavTab name="Transaction" path="/transactions/new" icon={Add} />+ <NavTab name="Settings" path="/settings" icon={Cog} />+ </div>+ );+}++type NavTabIconProps = {+ width: number;+ height: number;+};++type NavTabProps = {+ name: string;+ path: string;+ icon: ComponentType<NavTabIconProps>;+};++function NavTab({ icon: TabIcon, name, path }: NavTabProps) {+ return (+ <NavLink+ to={path}+ style={({ isActive }) => ({+ ...styles.noTapHighlight,+ alignItems: 'center',+ color: isActive ? theme.mobileNavItemSelected : theme.mobileNavItem,+ display: 'flex',+ flexDirection: 'column',+ textDecoration: 'none',+ })}+ >+ <TabIcon width={22} height={22} />+ {name}+ </NavLink>+ );+}diff --git a/packages/desktop-client/src/style/styles.ts b/packages/desktop-client/src/style/styles.tsindex b6bca971ec..7ec156c7b4 100644--- a/packages/desktop-client/src/style/styles.ts+++ b/packages/desktop-client/src/style/styles.ts@@ -83,7 +83,6 @@ export const styles = {fontSize: 16,// lineHeight: 22.4 // TODO: This seems like trouble, but what's the right value?},-delayedFadeIn: {animationName: keyframes({'0%': { opacity: 0 },@@ -98,6 +97,12 @@ export const styles = {textDecorationThickness: 2,textDecorationColor: theme.pillBorder,},+ noTapHighlight: {+ WebkitTapHighlightColor: 'transparent',+ ':focus': {+ outline: 'none',+ },+ },// Dynamically setlightScrollbar: null as CSSProperties | null,darkScrollbar: null as CSSProperties | null,diff --git a/upcoming-release-notes/1745.md b/upcoming-release-notes/1745.mdnew file mode 100644index 0000000000..356a8157cd--- /dev/null+++ b/upcoming-release-notes/1745.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [joel-jeremy,MatissJanis]+---++Hide mobile nav bar when scrolling