Skip to content

Commit

Permalink
Smoother mobile navtabs
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Nov 12, 2023
1 parent e418d76 commit 7eb1867
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 22 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.
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.
4 changes: 2 additions & 2 deletions packages/desktop-client/e2e/page-models/mobile-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class MobileNavigation {

async dragNavbarUp() {
await this.page
.locator('[role="navigation"]')
.dragTo(this.page.locator('[data-testid="budget-table"]'));
.getByRole('navigation')
.dragTo(this.page.getByTestId('budget-table'));
}
}
44 changes: 24 additions & 20 deletions packages/desktop-client/src/components/mobile/MobileNavTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ import { theme, styles, type CSSProperties } from '../../style';
import View from '../common/View';
import { useScroll } from '../ScrollProvider';

const ROW_HEIGHT = 70;
const COLUMN_COUNT = 3;

export default function MobileNavTabs() {
const { isNarrowWidth } = useResponsive();
const { scrollY } = useScroll();

const columnCount = 3;
const totalRowCount = 3;
const rowHeight = 70;

const navTabStyle = {
flex: `1 1 ${100 / columnCount}%`,
height: rowHeight,
flex: `1 1 ${100 / COLUMN_COUNT}%`,
height: ROW_HEIGHT,
padding: 10,
};

Expand All @@ -38,18 +37,18 @@ export default function MobileNavTabs() {
style: navTabStyle,
icon: Wallet,
},
{
name: 'Accounts',
path: '/accounts',
style: navTabStyle,
icon: PiggyBank,
},
{
name: 'Transaction',
path: '/transactions/new',
style: navTabStyle,
icon: Add,
},
{
name: 'Accounts',
path: '/accounts',
style: navTabStyle,
icon: PiggyBank,
},
{
name: 'Schedules (Soon)',
path: '/schedules/soon',
Expand All @@ -76,14 +75,14 @@ export default function MobileNavTabs() {
},
].map(tab => <NavTab key={tab.path} {...tab} />);

const bufferTabsCount = columnCount - (navTabs.length % columnCount);
const bufferTabsCount = COLUMN_COUNT - (navTabs.length % COLUMN_COUNT);
const bufferTabs = Array.from({ length: bufferTabsCount }).map((_, idx) => (
<div key={idx} style={navTabStyle} />
));

const totalHeight = rowHeight * totalRowCount;
const totalHeight = ROW_HEIGHT * COLUMN_COUNT;
const openY = 0;
const closeY = totalHeight - rowHeight;
const closeY = totalHeight - ROW_HEIGHT;
const hiddenY = totalHeight;

const [{ y }, api] = useSpring(() => ({ y: totalHeight }));
Expand Down Expand Up @@ -117,7 +116,12 @@ export default function MobileNavTabs() {
const previousScrollY = usePrevious(scrollY);

useEffect(() => {
if (scrollY > previousScrollY && previousScrollY !== 0) {
if (
scrollY &&
previousScrollY &&
scrollY > previousScrollY &&
previousScrollY !== 0
) {
hide();
} else {
close();
Expand All @@ -135,14 +139,14 @@ export default function MobileNavTabs() {
}) => {
// if the user drags up passed a threshold, then we cancel
// the drag so that the sheet resets to its open position
if (oy < -rowHeight) {
if (oy < 0) {
cancel();
}

// when the user releases the sheet, we check whether it passed
// the threshold for it to close, or if we reset it to its open position
if (last) {
if (oy > rowHeight * 0.5 || (vy > 0.5 && dy > 0)) {
if (oy > ROW_HEIGHT * 0.5 || (vy > 0.5 && dy > 0)) {
close(vy);
} else {
open({ canceled });
Expand All @@ -156,7 +160,7 @@ export default function MobileNavTabs() {
{
from: () => [0, y.get()],
filterTaps: true,
bounds: { top: rowHeight * 0.5, bottom: totalHeight * 0.5 },
bounds: { top: -totalHeight, bottom: totalHeight - ROW_HEIGHT },
axis: 'y',
rubberband: true,
},
Expand All @@ -177,7 +181,7 @@ export default function MobileNavTabs() {
position: 'fixed',
zIndex: 100,
bottom: 0,
display: isNarrowWidth ? 'flex' : 'none',
...(!isNarrowWidth && { display: 'none' }),
}}
>
<View
Expand Down

0 comments on commit 7eb1867

Please sign in to comment.