From cc8369e868ec684120a220dfa66845dad324b4a1 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 25 Feb 2025 09:20:37 -0800 Subject: [PATCH] Better tablet layout (#7656) * better tablet layout * adjust left nav spacing * add right nav to pwi * clearer logic * fix a couple screens that don't need the tablet layout * fix horiz scroll bar * fix double trending * fix ts-ignore * fix labeller screen * don't offset things within dialogs * fix load latest button (and add scale animation) * center loader on home screen * adjust break points * adjust left nav spacing * fix load latest btn (again) * add lang select to right nav if left nav is minimal * fix double scrollbar on tiny screens * fix scrollbar * fix type errors --- src/alf/breakpoints.ts | 15 ++++ src/components/Dialog/context.ts | 1 + src/components/Dialog/index.tsx | 1 + src/components/Dialog/index.web.tsx | 1 + src/components/Dialog/types.ts | 2 + src/components/Layout/Header/index.tsx | 10 ++- src/components/Layout/index.tsx | 43 ++++++++-- src/screens/Deactivated.tsx | 1 + src/screens/Profile/Sections/Labels.tsx | 10 +-- src/view/com/auth/SplashScreen.web.tsx | 8 +- src/view/com/posts/PostFeed.tsx | 9 +- src/view/com/util/Views.web.tsx | 33 +++++-- .../com/util/load-latest/LoadLatestBtn.tsx | 64 ++++++++------ src/view/screens/Home.tsx | 6 +- .../createNativeStackNavigatorWithAuth.tsx | 7 +- src/view/shell/desktop/LeftNav.tsx | 86 +++++++++---------- src/view/shell/desktop/RightNav.tsx | 36 +++++--- 17 files changed, 211 insertions(+), 122 deletions(-) diff --git a/src/alf/breakpoints.ts b/src/alf/breakpoints.ts index 9345856449..f30a4b4895 100644 --- a/src/alf/breakpoints.ts +++ b/src/alf/breakpoints.ts @@ -26,3 +26,18 @@ export function useBreakpoints(): Record & { } }, [gtPhone, gtMobile, gtTablet]) } + +/** + * Fine-tuned breakpoints for the shell layout + */ +export function useLayoutBreakpoints() { + const rightNavVisible = useMediaQuery({minWidth: 1075}) + const centerColumnOffset = useMediaQuery({minWidth: 1075, maxWidth: 1300}) + const leftNavMinimal = useMediaQuery({maxWidth: 1300}) + + return { + rightNavVisible, + centerColumnOffset, + leftNavMinimal, + } +} diff --git a/src/components/Dialog/context.ts b/src/components/Dialog/context.ts index b479bc7f06..331ff3f33a 100644 --- a/src/components/Dialog/context.ts +++ b/src/components/Dialog/context.ts @@ -14,6 +14,7 @@ export const Context = React.createContext({ nativeSnapPoint: BottomSheetSnapPoint.Hidden, disableDrag: false, setDisableDrag: () => {}, + isWithinDialog: false, }) export function useDialogContext() { diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index e70e4aef4c..463cadf3c8 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -154,6 +154,7 @@ export function Outer({ nativeSnapPoint: snapPoint, disableDrag, setDisableDrag, + isWithinDialog: true, }), [close, snapPoint, disableDrag, setDisableDrag], ) diff --git a/src/components/Dialog/index.web.tsx b/src/components/Dialog/index.web.tsx index a27222229d..1539546910 100644 --- a/src/components/Dialog/index.web.tsx +++ b/src/components/Dialog/index.web.tsx @@ -97,6 +97,7 @@ export function Outer({ nativeSnapPoint: 0, disableDrag: false, setDisableDrag: () => {}, + isWithinDialog: true, }), [close], ) diff --git a/src/components/Dialog/types.ts b/src/components/Dialog/types.ts index b87bfe2b71..32886f3ce7 100644 --- a/src/components/Dialog/types.ts +++ b/src/components/Dialog/types.ts @@ -44,6 +44,8 @@ export type DialogContextProps = { nativeSnapPoint: BottomSheetSnapPoint disableDrag: boolean setDisableDrag: React.Dispatch> + // in the event that the hook is used outside of a dialog + isWithinDialog: boolean } export type DialogControlOpenOptions = { diff --git a/src/components/Layout/Header/index.tsx b/src/components/Layout/Header/index.tsx index 3af0215c52..8ef114b442 100644 --- a/src/components/Layout/Header/index.tsx +++ b/src/components/Layout/Header/index.tsx @@ -14,6 +14,7 @@ import { TextStyleProp, useBreakpoints, useGutters, + useLayoutBreakpoints, useTheme, web, } from '#/alf' @@ -23,6 +24,7 @@ import {Menu_Stroke2_Corner0_Rounded as Menu} from '#/components/icons/Menu' import { BUTTON_VISUAL_ALIGNMENT_OFFSET, HEADER_SLOT_SIZE, + SCROLLBAR_OFFSET, } from '#/components/Layout/const' import {ScrollbarOffsetContext} from '#/components/Layout/context' import {Text} from '#/components/Typography' @@ -42,6 +44,7 @@ export function Outer({ const gutters = useGutters([0, 'base']) const {gtMobile} = useBreakpoints() const {isWithinOffsetView} = useContext(ScrollbarOffsetContext) + const {centerColumnOffset} = useLayoutBreakpoints() return ( {children} diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 489ebb2257..623478a6ac 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -13,7 +13,15 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context' import {isWeb} from '#/platform/detection' import {useShellLayout} from '#/state/shell/shell-layout' -import {atoms as a, useBreakpoints, useTheme, web} from '#/alf' +import { + atoms as a, + useBreakpoints, + useLayoutBreakpoints, + useTheme, + web, +} from '#/alf' +import {useDialogContext} from '#/components/Dialog' +import {SCROLLBAR_OFFSET} from '#/components/Layout/const' import {ScrollbarOffsetContext} from '#/components/Layout/context' export * from '#/components/Layout/const' @@ -47,6 +55,7 @@ export const Screen = React.memo(function Screen({ export type ContentProps = AnimatedScrollViewProps & { style?: StyleProp contentContainerStyle?: StyleProp + ignoreTabletLayoutOffset?: boolean } /** @@ -56,6 +65,7 @@ export const Content = React.memo(function Content({ children, style, contentContainerStyle, + ignoreTabletLayoutOffset, ...props }: ContentProps) { const t = useTheme() @@ -84,8 +94,10 @@ export const Content = React.memo(function Content({ ]} {...props}> {isWeb ? ( - // @ts-ignore web only -esb -
{children}
+
+ {/* @ts-expect-error web only -esb */} + {children} +
) : ( children )} @@ -138,10 +150,13 @@ export const KeyboardAwareContent = React.memo(function LayoutScrollView({ export const Center = React.memo(function LayoutContent({ children, style, + ignoreTabletLayoutOffset, ...props -}: ViewProps) { +}: ViewProps & {ignoreTabletLayoutOffset?: boolean}) { const {isWithinOffsetView} = useContext(ScrollbarOffsetContext) const {gtMobile} = useBreakpoints() + const {centerColumnOffset} = useLayoutBreakpoints() + const {isWithinDialog} = useDialogContext() const ctx = useMemo(() => ({isWithinOffsetView: true}), []) return ( @@ -168,6 +195,7 @@ export const Center = React.memo(function LayoutContent({ const WebCenterBorders = React.memo(function LayoutContent() { const t = useTheme() const {gtMobile} = useBreakpoints() + const {centerColumnOffset} = useLayoutBreakpoints() return gtMobile ? ( )} - - + - + ) } diff --git a/src/view/com/auth/SplashScreen.web.tsx b/src/view/com/auth/SplashScreen.web.tsx index eded803589..21b289e2ca 100644 --- a/src/view/com/auth/SplashScreen.web.tsx +++ b/src/view/com/auth/SplashScreen.web.tsx @@ -16,9 +16,9 @@ import { import {atoms as a, useTheme} from '#/alf' import {AppLanguageDropdown} from '#/components/AppLanguageDropdown' import {Button, ButtonText} from '#/components/Button' +import * as Layout from '#/components/Layout' import {InlineLinkText} from '#/components/Link' import {Text} from '#/components/Typography' -import {CenteredView} from '../util/Views' export const SplashScreen = ({ onDismiss, @@ -70,13 +70,13 @@ export const SplashScreen = ({ )} - +