Skip to content

Commit

Permalink
Merge branch 'master' into sankey_recharts
Browse files Browse the repository at this point in the history
  • Loading branch information
shaankhosla authored Oct 23, 2023
2 parents 92ffabc + 0af2987 commit 6dd09f3
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 51 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 7 additions & 50 deletions packages/desktop-client/src/components/FinancesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Route,
Routes,
Navigate,
NavLink,
useNavigate,
BrowserRouter,
useLocation,
useHref,
Expand All @@ -20,13 +20,8 @@ import checkForUpdateNotification from 'loot-core/src/client/update-notification
import * 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';

Expand All @@ -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';
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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>
Expand Down
54 changes: 54 additions & 0 deletions packages/desktop-client/src/components/ScrollProvider.tsx
Original file line number Diff line number Diff line change
@@ -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);
}
82 changes: 82 additions & 0 deletions packages/desktop-client/src/components/mobile/MobileNavTabs.tsx
Original file line number Diff line number Diff line change
@@ -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>
);
}
7 changes: 6 additions & 1 deletion packages/desktop-client/src/style/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -98,6 +97,12 @@ export const styles = {
textDecorationThickness: 2,
textDecorationColor: theme.pillBorder,
},
noTapHighlight: {
WebkitTapHighlightColor: 'transparent',
':focus': {
outline: 'none',
},
},
// Dynamically set
lightScrollbar: null as CSSProperties | null,
darkScrollbar: null as CSSProperties | null,
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1745.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [joel-jeremy,MatissJanis]
---

Hide mobile nav bar when scrolling

0 comments on commit 6dd09f3

Please sign in to comment.