diff --git a/src/components/Navigation/DebugTabView.tsx b/src/components/Navigation/DebugTabView.tsx index 536998617597..454123719a64 100644 --- a/src/components/Navigation/DebugTabView.tsx +++ b/src/components/Navigation/DebugTabView.tsx @@ -1,3 +1,4 @@ +import type {NavigationState} from '@react-navigation/native'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; @@ -10,27 +11,41 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useReportAttributes from '@hooks/useReportAttributes'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useRootNavigationState from '@hooks/useRootNavigationState'; import {useSidebarOrderedReportsState} from '@hooks/useSidebarOrderedReports'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import useWindowDimensions from '@hooks/useWindowDimensions'; +import getFocusedLeafScreenName from '@libs/Navigation/helpers/getFocusedLeafScreenName'; +import isTabRouteAtRoot from '@libs/Navigation/helpers/isTabRouteAtRoot'; import Navigation from '@libs/Navigation/Navigation'; import {getRouteForCurrentStep as getReimbursementAccountRouteForCurrentStep} from '@libs/ReimbursementAccountUtils'; -import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import {getChatTabBrickRoadReportID} from '@libs/WorkspacesSettingsUtils'; +import variables from '@styles/variables'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; +import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; +import SCREENS from '@src/SCREENS'; import type {ReimbursementAccount} from '@src/types/onyx'; import type IndicatorStatus from '@src/types/utils/IndicatorStatus'; import NAVIGATION_TABS from './NavigationTabBar/NAVIGATION_TABS'; -type DebugTabViewProps = { - selectedTab?: ValueOf; - chatTabBrickRoad: BrickRoad; -}; +function getActiveTabRoute(rootState: NavigationState | undefined) { + if (!rootState) { + return undefined; + } + // Multiple TAB_NAVIGATOR instances can exist in the root stack (e.g. workspace nav from RHP + // pushes a new one). Use `findLast` to read state from the most recent tab navigator, + // even when the focused root route is a modal — the bar should stay mounted under the RHP + // and just be visually covered by it. + const tabRoute = rootState.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR); + return tabRoute?.state?.routes?.[tabRoute.state.index ?? 0]; +} function getSettingsMessage(status: IndicatorStatus | undefined): TranslationPaths | undefined { switch (status) { @@ -103,17 +118,39 @@ function getSettingsRoute(status: IndicatorStatus | undefined, reimbursementAcco } } -function DebugTabView({selectedTab, chatTabBrickRoad}: DebugTabViewProps) { +type Props = { + selectedTab: ValueOf; +}; + +function DebugTabView({selectedTab}: Props) { const StyleUtils = useStyleUtils(); const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); + const {shouldUseNarrowLayout} = useResponsiveLayout(); + const {windowWidth} = useWindowDimensions(); const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT); const reportAttributes = useReportAttributes(); const {status, indicatorColor, policyIDWithErrors} = useIndicatorStatus(); - const {orderedReportIDs} = useSidebarOrderedReportsState(); + const {orderedReportIDs, chatTabBrickRoad} = useSidebarOrderedReportsState(); const icons = useMemoizedLazyExpensifyIcons(['DotIndicator']); + const isAtRoot = useRootNavigationState((rootState) => { + const activeRoute = getActiveTabRoute(rootState); + return activeRoute ? isTabRouteAtRoot(activeRoute) : false; + }); + + const isOnFullWidthTabRoot = useRootNavigationState((rootState) => { + const activeRoute = getActiveTabRoute(rootState); + if (!activeRoute) { + return false; + } + const focusedLeaf = getFocusedLeafScreenName(activeRoute.state) ?? activeRoute.name; + // Scoped to WORKSPACES_LIST — the only full-width tab root among the three tabs + // (Inbox/Settings/Workspaces) gated by the tab filter further below. + return focusedLeaf === SCREENS.WORKSPACES_LIST; + }); + const message = useMemo((): TranslationPaths | undefined => { if (selectedTab === NAVIGATION_TABS.INBOX) { if (chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) { @@ -152,7 +189,7 @@ function DebugTabView({selectedTab, chatTabBrickRoad}: DebugTabViewProps) { Navigation.navigate(ROUTES.DEBUG_REPORT.getRoute(reportID)); } } - if (selectedTab === NAVIGATION_TABS.SETTINGS) { + if (selectedTab === NAVIGATION_TABS.SETTINGS || selectedTab === NAVIGATION_TABS.WORKSPACES) { const route = getSettingsRoute(status, reimbursementAccount, policyIDWithErrors); if (route) { @@ -161,26 +198,49 @@ function DebugTabView({selectedTab, chatTabBrickRoad}: DebugTabViewProps) { } }, [selectedTab, chatTabBrickRoad, orderedReportIDs, reportAttributes, status, reimbursementAccount, policyIDWithErrors]); - if (!([NAVIGATION_TABS.INBOX, NAVIGATION_TABS.SETTINGS, NAVIGATION_TABS.WORKSPACES] as string[]).includes(selectedTab ?? '') || !indicator || !message) { + if ( + (shouldUseNarrowLayout && !isAtRoot) || + !([NAVIGATION_TABS.INBOX, NAVIGATION_TABS.SETTINGS, NAVIGATION_TABS.WORKSPACES] as string[]).includes(selectedTab) || + !indicator || + !message + ) { return null; } + let positionStyle: {bottom?: number; left: number; right?: number; width?: number}; + if (shouldUseNarrowLayout) { + positionStyle = {bottom: 0, left: 0, right: 0}; + } else if (isOnFullWidthTabRoot) { + positionStyle = {bottom: 0, left: variables.navigationTabBarSize, width: windowWidth - variables.navigationTabBarSize}; + } else { + positionStyle = {bottom: 0, left: variables.navigationTabBarSize, width: variables.sideBarWithLHBWidth - variables.cropBorderWidth}; + } + + // pAbsolute is only applied on wide layouts. On narrow layout the bar is placed by its parent + // (above the bottom tab bar), so detaching it with absolute positioning breaks both the FAB + // and the DebugTabView's own placement. return ( - - + + + {!!message && {translate(message)}} + +