From 0aaf11aa7b60927a0630ecd7f70fc4b55367c834 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 30 Dec 2025 19:56:05 +0200 Subject: [PATCH] fix drawer layout on mobile web (#9618) --- src/Navigation.tsx | 14 ++++++-- src/view/shell/index.web.tsx | 65 +++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/Navigation.tsx b/src/Navigation.tsx index fda4f41529..bf43eec6f1 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -5,7 +5,6 @@ import {i18n, type MessageDescriptor} from '@lingui/core' import {msg} from '@lingui/macro' import { type BottomTabBarProps, - type BottomTabNavigatorProps, createBottomTabNavigator, } from '@react-navigation/bottom-tabs' import { @@ -637,7 +636,11 @@ function commonScreens(Stack: typeof Flat, unreadCountLabel?: string) { * The TabsNavigator is used by native mobile to represent the routes * in 3 distinct tab-stacks with a different root screen on each. */ -function TabsNavigator({layout}: {layout: BottomTabNavigatorProps['layout']}) { +function TabsNavigator({ + layout, +}: { + layout: React.ComponentProps['layout'] +}) { const tabBar = useCallback( (props: JSX.IntrinsicAttributes & BottomTabBarProps) => ( @@ -759,7 +762,11 @@ function MessagesTabNavigator() { * The FlatNavigator is used by Web to represent the routes * in a single ("flat") stack. */ -const FlatNavigator = () => { +const FlatNavigator = ({ + layout, +}: { + layout: React.ComponentProps['layout'] +}) => { const t = useTheme() const numUnread = useUnreadNotifications() const screenListeners = useWebScrollRestoration() @@ -767,6 +774,7 @@ const FlatNavigator = () => { return ( () const closeAllActiveElements = useCloseAllActiveElements() - const {_} = useLingui() - const showDrawer = !isDesktop && isDrawerOpen - const [showDrawerDelayedExit, setShowDrawerDelayedExit] = useState(showDrawer) const {state: policyUpdateState} = usePolicyUpdateContext() const welcomeModalControl = useWelcomeModal() - useLayoutEffect(() => { - if (showDrawer !== showDrawerDelayedExit) { - if (showDrawer) { - setShowDrawerDelayedExit(true) - } else { - const timeout = setTimeout(() => { - setShowDrawerDelayedExit(false) - }, 160) - return () => clearTimeout(timeout) - } - } - }, [showDrawer, showDrawerDelayedExit]) - useComposerKeyboardShortcut() useIntentHandler() @@ -74,10 +53,16 @@ function ShellInner() { return unsubscribe }, [navigator, closeAllActiveElements]) + const drawerLayout = useCallback( + ({children}: {children: React.ReactNode}) => ( + {children} + ), + [], + ) return ( <> - + @@ -100,6 +85,36 @@ function ShellInner() { )} + + + ) +} + +function DrawerLayout({children}: {children: React.ReactNode}) { + const t = useTheme() + const isDrawerOpen = useIsDrawerOpen() + const setDrawerOpen = useSetDrawerOpen() + const {gtTablet} = useBreakpoints() + const {_} = useLingui() + const showDrawer = !gtTablet && isDrawerOpen + const [showDrawerDelayedExit, setShowDrawerDelayedExit] = useState(showDrawer) + + useLayoutEffect(() => { + if (showDrawer !== showDrawerDelayedExit) { + if (showDrawer) { + setShowDrawerDelayedExit(true) + } else { + const timeout = setTimeout(() => { + setShowDrawerDelayedExit(false) + }, 160) + return () => clearTimeout(timeout) + } + } + }, [showDrawer, showDrawerDelayedExit]) + + return ( + <> + {children} {showDrawerDelayedExit && ( <> @@ -137,8 +152,6 @@ function ShellInner() { )} - - ) }