From 40eb45baad0c8c41ce35a2d03ac299fbbc2a3b53 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 1 Dec 2024 17:13:52 -0600 Subject: [PATCH] Build out header, WIP --- src/alf/index.tsx | 1 + src/alf/util/useGutterStyles.ts | 21 ++++ src/components/Layout.tsx | 104 +++++++++++++++--- src/screens/Settings/AccountSettings.tsx | 8 +- .../Settings/components/SettingsList.tsx | 5 +- src/view/shell/desktop/LeftNav.tsx | 54 +-------- 6 files changed, 125 insertions(+), 68 deletions(-) create mode 100644 src/alf/util/useGutterStyles.ts diff --git a/src/alf/index.tsx b/src/alf/index.tsx index 5d08722ff4..a96803c561 100644 --- a/src/alf/index.tsx +++ b/src/alf/index.tsx @@ -20,6 +20,7 @@ export * from '#/alf/types' export * from '#/alf/util/flatten' export * from '#/alf/util/platform' export * from '#/alf/util/themeSelector' +export * from '#/alf/util/useGutterStyles' export type Alf = { themeName: ThemeName diff --git a/src/alf/util/useGutterStyles.ts b/src/alf/util/useGutterStyles.ts new file mode 100644 index 0000000000..64b246fdd2 --- /dev/null +++ b/src/alf/util/useGutterStyles.ts @@ -0,0 +1,21 @@ +import React from 'react' + +import {atoms as a, useBreakpoints, ViewStyleProp} from '#/alf' + +export function useGutterStyles({ + top, + bottom, +}: { + top?: boolean + bottom?: boolean +} = {}) { + const {gtMobile} = useBreakpoints() + return React.useMemo(() => { + return [ + a.px_lg, + top && a.pt_md, + bottom && a.pb_md, + gtMobile && [a.px_xl, top && a.pt_lg, bottom && a.pb_lg], + ] + }, [gtMobile, top, bottom]) +} diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 248e545c3e..8d5ed56af2 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -7,11 +7,18 @@ import { } from 'react-native-keyboard-controller' import Animated, {AnimatedScrollViewProps} from 'react-native-reanimated' import {useSafeAreaInsets} from 'react-native-safe-area-context' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {useNavigation} from '@react-navigation/native' +import {NavigationProp} from '#/lib/routes/types' import {isWeb} from '#/platform/detection' import {ViewHeader} from '#/view/com/util/ViewHeader' import {CenteredView} from '#/view/com/util/Views' -import {atoms as a, useBreakpoints, useTheme, ViewStyleProp} from '#/alf' +import {atoms as a, useBreakpoints, useGutterStyles,useTheme} from '#/alf' +import {Button, ButtonIcon} from '#/components/Button' +import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron' +import {Text} from '#/components/Typography' // Every screen should have a Layout component wrapping it. // This component provides a default padding for the top of the screen. @@ -190,28 +197,95 @@ export const Center = React.forwardRef(function LayoutContent( ) }) -export function Gutter({ +export function HeaderNew({children}: {children: React.ReactNode}) { + const t = useTheme() + const gutter = useGutterStyles({top: true, bottom: true}) + + return ( + + + {children} + + + ) +} + +HeaderNew.BackButton = function HeaderBackButton() { + const {_} = useLingui() + const navigation = useNavigation() + + const onPressBack = React.useCallback(() => { + if (navigation.canGoBack()) { + navigation.goBack() + } else { + navigation.navigate('Home') + } + }, [navigation]) + + return ( + + ) +} + +HeaderNew.Content = function HeaderContent({ children, - top, - bottom, - style, -}: ViewStyleProp & { + right, +}: { + children: React.ReactNode + right?: React.ReactNode +}) { + return ( + + {children} + {right && {right}} + + ) +} + +HeaderNew.TitleText = function HeaderTitleText({ + children, +}: { children: React.ReactNode - top?: boolean - bottom?: boolean }) { const {gtMobile} = useBreakpoints() return ( - {children} - + + ) +} + +HeaderNew.SubtitleText = function HeaderSubtitleText({ + children, +}: { + children: React.ReactNode +}) { + const t = useTheme() + return ( + + {children} + ) } diff --git a/src/screens/Settings/AccountSettings.tsx b/src/screens/Settings/AccountSettings.tsx index 2495a0f2f9..0c2d488b39 100644 --- a/src/screens/Settings/AccountSettings.tsx +++ b/src/screens/Settings/AccountSettings.tsx @@ -38,8 +38,14 @@ export function AccountSettingsScreen({}: Props) { return ( - + + + + Account + + + diff --git a/src/screens/Settings/components/SettingsList.tsx b/src/screens/Settings/components/SettingsList.tsx index 520df41187..ed02d87467 100644 --- a/src/screens/Settings/components/SettingsList.tsx +++ b/src/screens/Settings/components/SettingsList.tsx @@ -2,7 +2,7 @@ import React, {useContext, useMemo} from 'react' import {GestureResponderEvent, StyleProp, View, ViewStyle} from 'react-native' import {HITSLOP_10} from '#/lib/constants' -import {atoms as a, useTheme, ViewStyleProp} from '#/alf' +import {atoms as a, useGutterStyles,useTheme, ViewStyleProp} from '#/alf' import * as Button from '#/components/Button' import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRightIcon} from '#/components/icons/Chevron' import {Link, LinkProps} from '#/components/Link' @@ -80,6 +80,7 @@ export function Item({ iconInset?: boolean style?: StyleProp }) { + const gutter = useGutterStyles() const context = useContext(ItemContext) const childContext = useMemo(() => { if (typeof destructive !== 'boolean') return context @@ -88,7 +89,7 @@ export function Item({ return ( () - const {_} = useLingui() - const shouldShow = useNavigationState( - state => - !isStateAtTabRoot(state) && - !HIDDEN_BACK_BNT_ROUTES.includes(getCurrentRoute(state).name), - ) - - const onPressBack = React.useCallback(() => { - if (navigation.canGoBack()) { - navigation.goBack() - } else { - navigation.navigate('Home') - } - }, [navigation]) - - if (!shouldShow || isTablet) { - return <> - } - return ( - - - - ) -} - interface NavItemProps { count?: string href: string @@ -381,8 +337,6 @@ export function DesktopLeftNav() { {hasSession && ( <> - -