Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 80 additions & 20 deletions src/components/Navigation/DebugTabView.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<typeof NAVIGATION_TABS>;
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) {
Expand Down Expand Up @@ -103,17 +118,39 @@ function getSettingsRoute(status: IndicatorStatus | undefined, reimbursementAcco
}
}

function DebugTabView({selectedTab, chatTabBrickRoad}: DebugTabViewProps) {
type Props = {
selectedTab: ValueOf<typeof NAVIGATION_TABS>;
};

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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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};
}
Comment on lines +211 to +217

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #99976 BugZero checklist:

This PR missing handle the wide-layout debug banner overlaps and partially covers the last row of the Workspaces list. and renders at sidebar width on Domains. Moving the banner out of flow fixed the blank-space bug here, but no space-reservation contract was added for full-width tab roots, so any account-level indicator now paints over list content. The fix in #100766 reserves the banner height in the wide-layout pages and corrects the Domains geometry.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOMAINS_LIST did not exist when this PR merged. #90204 added that full-width page and never updated the debug whitelist


// 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 (
<View
testID="DebugTabView"
style={[StyleUtils.getBackgroundColorStyle(theme.cardBG), styles.p3, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}
testID="DebugTabViewContainer"
style={[shouldUseNarrowLayout ? positionStyle : {...styles.pAbsolute, ...positionStyle}]}
pointerEvents="box-none"
>
<View style={[styles.flexRow, styles.gap2, styles.flex1, styles.alignItemsCenter]}>
<Icon
src={icons.DotIndicator}
fill={indicator}
<View
testID="DebugTabView"
style={[StyleUtils.getBackgroundColorStyle(theme.cardBG), styles.p3, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}
>
<View style={[styles.flexRow, styles.gap2, styles.flex1, styles.alignItemsCenter]}>
<Icon
src={icons.DotIndicator}
fill={indicator}
/>
{!!message && <Text style={[StyleUtils.getColorStyle(theme.text), styles.lh20]}>{translate(message)}</Text>}
</View>
<Button
text={translate('common.view')}
onPress={navigateTo}
/>
{!!message && <Text style={[StyleUtils.getColorStyle(theme.text), styles.lh20]}>{translate(message)}</Text>}
</View>
<Button
text={translate('common.view')}
onPress={navigateTo}
/>
</View>
);
}
Expand Down
Comment thread
borys3kk marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {ValueOf} from 'type-fest';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';
import NAVIGATION_TABS from './NAVIGATION_TABS';

const ROUTE_TO_NAVIGATION_TAB: Record<string, ValueOf<typeof NAVIGATION_TABS>> = {
[SCREENS.HOME]: NAVIGATION_TABS.HOME,
[NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: NAVIGATION_TABS.INBOX,
[NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR]: NAVIGATION_TABS.SEARCH,
[NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: NAVIGATION_TABS.SETTINGS,
[NAVIGATORS.WORKSPACE_NAVIGATOR]: NAVIGATION_TABS.WORKSPACES,
};

export default ROUTE_TO_NAVIGATION_TAB;
20 changes: 6 additions & 14 deletions src/components/Navigation/NavigationTabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ function NavigationTabBar({selectedTab, shouldShowFloatingButtons = true}: Navig

const StyleUtils = useStyleUtils();

const shouldRenderDebugTabViewOnWideLayout = !!isDebugModeEnabled;

let inboxStatusIndicatorColor: string | undefined;
if (chatTabBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) {
inboxStatusIndicatorColor = theme.iconSuccessFill;
Expand Down Expand Up @@ -132,15 +130,14 @@ function NavigationTabBar({selectedTab, shouldShowFloatingButtons = true}: Navig
});
};

// shouldShowFloatingButtons is false for the swipe-back duplicate tab bar rendered via
// bottomContent — gating the debug view on it prevents it from appearing in that copy too.
const shouldShowDebugTabView = !!isDebugModeEnabled && shouldShowFloatingButtons;

if (!shouldUseNarrowLayout) {
return (
<>
{shouldRenderDebugTabViewOnWideLayout && (
<DebugTabView
selectedTab={selectedTab}
chatTabBrickRoad={chatTabBrickRoad}
/>
)}
{shouldShowDebugTabView && <DebugTabView selectedTab={selectedTab} />}
<View
style={styles.leftNavigationTabBarContainer}
testID="NavigationTabBar"
Expand Down Expand Up @@ -219,12 +216,7 @@ function NavigationTabBar({selectedTab, shouldShowFloatingButtons = true}: Navig

return (
<>
{!!isDebugModeEnabled && (
<DebugTabView
selectedTab={selectedTab}
chatTabBrickRoad={chatTabBrickRoad}
/>
)}
{shouldShowDebugTabView && <DebugTabView selectedTab={selectedTab} />}
<View
style={styles.navigationTabBarContainer}
testID="NavigationTabBar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function TabNavigator() {
const navigation = useNavigation();
const parentNavigation = navigation.getParent();
const focusedRouteName = useNavigationState((state) => findFocusedRoute(state)?.name);

useEffect(() => {
if (!shouldUseNarrowLayout || !parentNavigation) {
return;
Expand Down
56 changes: 7 additions & 49 deletions src/libs/Navigation/AppNavigator/Navigators/TabNavigatorBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,22 @@ import type {ValueOf} from 'type-fest';
import {useFullScreenBlockingViewState} from '@components/FullScreenBlockingViewContextProvider';
import NavigationTabBar from '@components/Navigation/NavigationTabBar';
import NAVIGATION_TABS from '@components/Navigation/NavigationTabBar/NAVIGATION_TABS';
import ROUTE_TO_NAVIGATION_TAB from '@components/Navigation/NavigationTabBar/ROUTE_TO_NAVIGATION_TAB';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSafeAreaPaddings from '@hooks/useSafeAreaPaddings';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import getFocusedLeafScreenName from '@libs/Navigation/helpers/getFocusedLeafScreenName';
import isTabRouteAtRoot from '@libs/Navigation/helpers/isTabRouteAtRoot';
import cancelTabNavigationSpans from '@libs/telemetry/cancelTabNavigationSpans';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';

const ROUTE_TO_NAVIGATION_TAB: Record<string, ValueOf<typeof NAVIGATION_TABS>> = {
[SCREENS.HOME]: NAVIGATION_TABS.HOME,
[NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: NAVIGATION_TABS.INBOX,
[NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR]: NAVIGATION_TABS.SEARCH,
[NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: NAVIGATION_TABS.SETTINGS,
[NAVIGATORS.WORKSPACE_NAVIGATOR]: NAVIGATION_TABS.WORKSPACES,
};

const NAVIGATION_TAB_TO_SPAN: Partial<Record<ValueOf<typeof NAVIGATION_TABS>, string>> = {
[NAVIGATION_TABS.INBOX]: CONST.TELEMETRY.SPAN_NAVIGATE_TO_INBOX_TAB,
[NAVIGATION_TABS.SEARCH]: CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS,
};

// Count as tab-root when they surface as the resolved leaf.
const TAB_WRAPPER_NAVIGATORS = new Set<string>([
NAVIGATORS.REPORTS_SPLIT_NAVIGATOR,
NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR,
NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR,
NAVIGATORS.WORKSPACE_NAVIGATOR,
]);

/**
* Leaf screen names that represent the root/landing view of each tab.
* Used to decide tab-bar visibility.
*/
const SCREENS_WITH_TAB_BAR = new Set<string>([
SCREENS.HOME,
SCREENS.INBOX,
SCREENS.SEARCH.ROOT,
SCREENS.SETTINGS.ROOT,
SCREENS.WORKSPACES_LIST,
SCREENS.WORKSPACE.INITIAL,
SCREENS.DOMAIN.INITIAL,
]);

const isAtTabRootLevel = (name: string | undefined): boolean => !!name && (SCREENS_WITH_TAB_BAR.has(name) || TAB_WRAPPER_NAVIGATORS.has(name));

// Deepest `screen` in a `{screen, params}` chain (e.g. WORKSPACE_NAV → WORKSPACE_SPLIT_NAV → WORKSPACE.INITIAL).
const getPushTargetLeaf = (params: unknown): string | undefined => {
const p = params as {screen?: unknown; params?: unknown} | undefined;
if (typeof p?.screen !== 'string') {
return undefined;
}
return getPushTargetLeaf(p.params) ?? p.screen;
};

/**
* Custom tab bar rendered by the BottomTabNavigator. Only receives `state` (not the
* full BottomTabBarProps) to avoid `descriptors` thrashing memoization.
Expand All @@ -75,11 +34,7 @@ function TabNavigatorBar({state}: Pick<BottomTabBarProps, 'state'>) {
const StyleUtils = useStyleUtils();
const activeRoute = state.routes[state.index];
const selectedTab = ROUTE_TO_NAVIGATION_TAB[activeRoute?.name ?? SCREENS.HOME] ?? NAVIGATION_TABS.HOME;
// Trust the focused leaf as the source of truth. Fall back to the push target only when the navigator
// state hasn't hydrated yet (Android), so the tab bar doesn't flash on the push target during the transition.
// Tab-level params can be stale after within-tab back navigation, so they must not override an already-hydrated focused leaf.
const focusedLeaf = getFocusedLeafScreenName(activeRoute?.state);
const isAtRoot = isAtTabRootLevel(focusedLeaf ?? getPushTargetLeaf(activeRoute?.params));
const isAtRoot = isTabRouteAtRoot(activeRoute);
// --- Narrow-only animation logic (hooks must run unconditionally per Rules of Hooks) ---
// On native, screens also render the tab bar via bottomContent for swipe-back animations.
// Delay showing this navigator's tab bar only when navigating back from a deeper screen
Expand Down Expand Up @@ -126,7 +81,10 @@ function TabNavigatorBar({state}: Pick<BottomTabBarProps, 'state'>) {
}

return (
<View style={styles.overflowHidden}>
<View
style={[styles.tabNavigatorBarContainer]}
pointerEvents="box-none"
>
<NavigationTabBar selectedTab={selectedTab} />
</View>
);
Expand Down
56 changes: 56 additions & 0 deletions src/libs/Navigation/helpers/isTabRouteAtRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type {NavigationState, PartialState} from '@react-navigation/native';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';
import getFocusedLeafScreenName from './getFocusedLeafScreenName';

/**
* Leaf screen names that represent the root/landing view of each tab.
* Used to decide tab-bar visibility.
*/
const SCREENS_WITH_TAB_BAR = new Set<string>([
SCREENS.HOME,
SCREENS.INBOX,
SCREENS.SEARCH.ROOT,
SCREENS.SETTINGS.ROOT,
SCREENS.WORKSPACES_LIST,
SCREENS.WORKSPACE.INITIAL,
SCREENS.DOMAIN.INITIAL,
]);

// Count as tab-root when they surface as the resolved leaf.
const TAB_WRAPPER_NAVIGATORS = new Set<string>([
NAVIGATORS.REPORTS_SPLIT_NAVIGATOR,
NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR,
NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR,
NAVIGATORS.WORKSPACE_NAVIGATOR,
]);

const isAtTabRootLevel = (name: string | undefined): boolean => !name || SCREENS_WITH_TAB_BAR.has(name) || TAB_WRAPPER_NAVIGATORS.has(name);

// Deepest `screen` in a `{screen, params}` chain (e.g. WORKSPACE_NAV → WORKSPACE_SPLIT_NAV → WORKSPACE.INITIAL).
const getPushTargetLeaf = (params: unknown): string | undefined => {
const p = params as {screen?: unknown; params?: unknown} | undefined;
if (typeof p?.screen !== 'string') {
return undefined;
}
return getPushTargetLeaf(p.params) ?? p.screen;
};

type TabRouteLike = {
state?: NavigationState | PartialState<NavigationState>;
params?: unknown;
};

/**
* Returns true when the active tab route resolves to a tab's root view.
* Trusts the focused leaf as the source of truth. Falls back to the push target only when the
* navigator state hasn't hydrated yet (Android cold start), so the tab bar doesn't flash on the
* push target during the transition. Tab-level params can be stale after within-tab back
* navigation, so they must not override an already-hydrated focused leaf.
*/
function isTabRouteAtRoot(route: TabRouteLike | undefined): boolean {
const focusedLeaf = getFocusedLeafScreenName(route?.state);
return isAtTabRootLevel(focusedLeaf ?? getPushTargetLeaf(route?.params));
}

export default isTabRouteAtRoot;
7 changes: 7 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,13 @@ const staticStyles = (theme: ThemeColors) =>
height: variables.bottomTabHeight,
},

tabNavigatorBarContainer: {
zIndex: 1,
width: variables.navigationTabBarSize + variables.sideBarWithLHBWidth,
marginRight: -variables.sideBarWithLHBWidth,
overflow: 'visible',
},

navigationTabBarContainer: {
flexDirection: 'row',
height: variables.bottomTabHeight,
Expand Down
Loading
Loading