Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const useSplitNavigatorScreenOptions = () => {
headerShown: false,
title: CONFIG.SITE_TITLE,
animation: shouldUseNarrowLayout ? undefined : Animations.NONE,
animationTypeForReplace: 'pop',
web: {
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator({props, isFullScreenModal: true, shouldAnimateSidePanel: true}),
cardStyle: shouldUseNarrowLayout ? StyleUtils.getNavigationModalCardStyle() : themeStyles.h100,
Expand Down
9 changes: 8 additions & 1 deletion src/libs/Navigation/NavigationRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
return;
}

Navigation.setShouldPopAllStateOnUP(!shouldUseNarrowLayout);
// After resizing the screen from wide to narrow, if we have visited multiple central screens, we want to go back to the LHN screen, so we set shouldPopAllStateOnUP to true.
// Now when this value is true, Navigation.goBack with the option {shouldPopToTop: true} will remove all visited central screens in the given tab from the navigation stack and go back to the LHN.
// More context here: https://github.com/Expensify/App/pull/59300
if (!shouldUseNarrowLayout) {
return;
}

Navigation.setShouldPopAllStateOnUP(true);
Comment thread
WojtekBoman marked this conversation as resolved.
}, [shouldUseNarrowLayout]);

useEffect(() => {
Expand Down
28 changes: 28 additions & 0 deletions src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import navigationRef from '@libs/Navigation/navigationRef';
import NAVIGATORS from '@src/NAVIGATORS';
import ROUTES from '@src/ROUTES';

/**
* If there are already other screens open in WorkspaceSplitNavigator, we return to the previous one.
* If not, from the central screen in WorkspaceSplitNavigator we should return to the WorkspaceInitialPage.
*/
function goBackFromWorkspaceCentralScreen(policyID: string | undefined) {
const rootState = navigationRef.getRootState();
const lastRoute = rootState.routes.at(-1);

if (lastRoute?.name !== NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) {
Log.hmmm('[goBackFromWorkspaceCentralScreen] goBackFromWorkspaceCentralScreen was called from a different navigator than WorkspaceSplitNavigator.');
return;
}

if (lastRoute.state?.routes && lastRoute.state.routes.length > 1) {
Navigation.goBack(undefined, {shouldPopToTop: true});
return;
}

Navigation.goBack(ROUTES.WORKSPACE_INITIAL.getRoute(policyID));
}

export default goBackFromWorkspaceCentralScreen;
2 changes: 1 addition & 1 deletion src/pages/TeachersUnite/SaveTheWorldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function SaveTheWorldPage() {
title={translate('sidebarScreen.saveTheWorld')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack()}
onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})}
icon={Illustrations.TeachersUnite}
shouldUseHeadlineHeader
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/AboutPage/AboutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function AboutPage() {
title={translate('initialSettingsPage.about')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS, {shouldPopToTop: true})}
icon={Illustrations.PalmTree}
shouldUseHeadlineHeader
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Preferences/PreferencesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function PreferencesPage() {
shouldUseHeadlineHeader
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack()}
onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})}

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.

@WojtekBoman Why this was added here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was added to pop all central screens when navigating back after resizing the window:

Screen.Recording.2025-04-04.at.16.24.35.mov

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.

@WojtekBoman One last thing, I think you forgot About, Troubleshoot, and Save the world pages here.

@WojtekBoman WojtekBoman Apr 4, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I pushed a new commit that covers it. Thanks for noticing that!

/>
<ScrollView contentContainerStyle={styles.pt3}>
<View style={[styles.flex1, shouldUseNarrowLayout ? styles.workspaceSectionMobile : styles.workspaceSection]}>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function ProfilePage() {
>
<HeaderWithBackButton
title={translate('common.profile')}
onBackButtonPress={() => Navigation.goBack(route.params?.backTo)}
onBackButtonPress={() => Navigation.goBack(route.params?.backTo, {shouldPopToTop: true})}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
icon={Illustrations.Profile}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Security/SecuritySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function SecuritySettingsPage() {
<HeaderWithBackButton
title={translate('initialSettingsPage.security')}
shouldShowBackButton={shouldUseNarrowLayout}
onBackButtonPress={() => Navigation.goBack()}
onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})}
icon={Illustrations.LockClosed}
shouldUseHeadlineHeader
shouldDisplaySearchRouter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function SubscriptionSettingsPage({route}: SubscriptionSettingsPageProps) {
>
<HeaderWithBackButton
title={translate('workspace.common.subscription')}
onBackButtonPress={() => Navigation.goBack(backTo)}
onBackButtonPress={() => Navigation.goBack(backTo, {shouldPopToTop: true})}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
icon={Illustrations.CreditCardsNew}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Troubleshoot/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function TroubleshootPage() {
title={translate('initialSettingsPage.aboutPage.troubleshoot')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS, {shouldPopToTop: true})}
icon={Illustrations.Lightbulb}
shouldUseHeadlineHeader
/>
Expand Down
1 change: 1 addition & 0 deletions src/pages/settings/Wallet/WalletPage/WalletPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) {
shouldUseHeadlineHeader
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})}
/>
);

Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {removeApprovalWorkflow as removeApprovalWorkflowAction, updateApprovalWo
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import {formatPhoneNumber as formatPhoneNumberUtil} from '@libs/LocalePhoneNumber';
import Log from '@libs/Log';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -680,7 +681,7 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
turnOffMobileSelectionMode();
return;
}
Navigation.goBack();
goBackFromWorkspaceCentralScreen(policyID);
}}
>
{() => (
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {filterInactiveCards, getAllCardsForWorkspace, getCompanyFeeds, isSmartLimitEnabled as isSmartLimitEnabledUtil} from '@libs/CardUtils';
import {getLatestErrorField} from '@libs/ErrorUtils';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -465,6 +466,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
shouldUseHeadlineHeader
title={translate('workspace.common.moreFeatures')}
shouldShowBackButton={shouldUseNarrowLayout}
onBackButtonPress={() => goBackFromWorkspaceCentralScreen(policyID)}
/>

<ScrollView>
Expand Down
10 changes: 9 additions & 1 deletion src/pages/workspace/WorkspaceOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from '@libs/actions/Policy/Policy';
import {filterInactiveCards} from '@libs/CardUtils';
import {getLatestErrorField} from '@libs/ErrorUtils';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import resetPolicyIDInNavigationState from '@libs/Navigation/helpers/resetPolicyIDInNavigationState';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
Expand Down Expand Up @@ -189,7 +190,14 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
shouldShowNonAdmin
icon={Illustrations.Building}
shouldShowNotFoundPage={policy === undefined}
onBackButtonPress={() => Navigation.goBack(backTo)}
onBackButtonPress={() => {
if (backTo) {
Navigation.goBack(backTo);
return;
}

goBackFromWorkspaceCentralScreen(policy?.id);
}}
>
{(hasVBA?: boolean) => (
<View style={[styles.flex1, styles.mt3, shouldUseNarrowLayout ? styles.workspaceSectionMobile : styles.workspaceSection]}>
Expand Down
17 changes: 16 additions & 1 deletion src/pages/workspace/WorkspacePageWithSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {openWorkspaceView} from '@libs/actions/BankAccounts';
import BankAccount from '@libs/models/BankAccount';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -161,6 +162,20 @@ function WorkspacePageWithSections({
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [policy, shouldShowNonAdmin, shouldShowPolicy]);

const handleOnBackButtonPress = () => {
if (onBackButtonPress) {
onBackButtonPress();
return;
}

if (backButtonRoute) {
Navigation.goBack(backButtonRoute);
return;
}

goBackFromWorkspaceCentralScreen(policyID);
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={includeSafeAreaPaddingBottom}
Expand All @@ -179,7 +194,7 @@ function WorkspacePageWithSections({
>
<HeaderWithBackButton
title={headerText}
onBackButtonPress={() => (onBackButtonPress ? onBackButtonPress() : Navigation.goBack(backButtonRoute))}
onBackButtonPress={handleOnBackButtonPress}
shouldShowBackButton={shouldUseNarrowLayout || shouldShowBackButton}
icon={icon ?? undefined}
style={styles.headerBarDesktopHeight}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {isAuthenticationError, isConnectionInProgress, isConnectionUnverified, r
import {shouldShowQBOReimbursableExportDestinationAccountError} from '@libs/actions/connections/QuickbooksOnline';
import {getAssignedSupportData} from '@libs/actions/Policy/Policy';
import {isExpensifyCardFullySetUp} from '@libs/CardUtils';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import {
areSettingsInErrorFields,
findCurrentXeroOrganization,
Expand Down Expand Up @@ -534,6 +535,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
icon={Illustrations.Accounting}
shouldUseHeadlineHeader
threeDotsAnchorPosition={threeDotsAnchorPosition}
onBackButtonPress={() => goBackFromWorkspaceCentralScreen(policyID)}
/>
<ScrollView contentContainerStyle={styles.pt3}>
<View style={[styles.flex1, shouldUseNarrowLayout ? styles.workspaceSectionMobile : styles.workspaceSection]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {isConnectionInProgress} from '@libs/actions/connections';
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import localeCompare from '@libs/LocaleCompare';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -417,7 +418,13 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
turnOffMobileSelectionMode();
return;
}
Navigation.goBack(backTo);

if (backTo) {
Navigation.goBack(backTo);
return;
}

goBackFromWorkspaceCentralScreen(policyId);
}}
shouldShowThreeDotsButton
style={styles.headerBarDesktopHeight}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '@libs/actions/Policy/DistanceRate';
import {convertAmountToDisplayString} from '@libs/CurrencyUtils';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {getDistanceRateCustomUnit} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -356,7 +357,7 @@ function PolicyDistanceRatesPage({
turnOffMobileSelectionMode();
return;
}
Navigation.goBack();
goBackFromWorkspaceCentralScreen(policyID);
}}
>
{!shouldUseNarrowLayout && headerButtons}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';
import {getLastFourDigits} from '@libs/BankAccountUtils';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import Navigation from '@navigation/Navigation';
import type {SettingsNavigatorParamList} from '@navigation/types';
Expand Down Expand Up @@ -48,7 +49,10 @@ function WorkspaceCardSettingsPage({route}: WorkspaceCardSettingsPageProps) {
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
>
<HeaderWithBackButton title={translate('workspace.common.settings')} />
<HeaderWithBackButton
title={translate('workspace.common.settings')}
onBackButtonPress={() => goBackFromWorkspaceCentralScreen(policyID)}

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.

We placed this logic on the wrong screen, which caused #60451

/>
<ScrollView contentContainerStyle={styles.flexGrow1}>
<View>
<OfflineWithFeedback errorRowStyles={styles.mh5}>
Expand Down
9 changes: 8 additions & 1 deletion src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useThreeDotsAnchorPosition from '@hooks/useThreeDotsAnchorPosition';
import {convertAmountToDisplayString} from '@libs/CurrencyUtils';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import localeCompare from '@libs/LocaleCompare';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -382,7 +383,13 @@ function WorkspacePerDiemPage({route}: WorkspacePerDiemPageProps) {
turnOffMobileSelectionMode();
return;
}
Navigation.goBack(backTo);

if (backTo) {
Navigation.goBack(backTo);
return;
}

goBackFromWorkspaceCentralScreen(policyID);
}}
shouldShowThreeDotsButton
threeDotsMenuItems={threeDotsMenuItems}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {isConnectionInProgress} from '@libs/actions/connections';
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import localeCompare from '@libs/LocaleCompare';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -256,7 +257,7 @@ function WorkspaceReportFieldsPage({
turnOffMobileSelectionMode();
return;
}
Navigation.goBack();
goBackFromWorkspaceCentralScreen(policyID);
}}
>
{!shouldUseNarrowLayout && !hasReportAccountingConnections && getHeaderButtons()}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {clearPolicyTagErrors, deletePolicyTags, downloadTagsCSV, openPolicyTagsPage, setPolicyTagsRequired, setWorkspaceTagEnabled} from '@libs/actions/Policy/Tag';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import localeCompare from '@libs/LocaleCompare';
import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -452,7 +453,13 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
turnOffMobileSelectionMode();
return;
}
Navigation.goBack(backTo);

if (backTo) {
Navigation.goBack(backTo);
return;
}

goBackFromWorkspaceCentralScreen(policyID);

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.

@WojtekBoman I believe there are some pages left like per diem page where you haven't applied these changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I pushed a new commit, now it covers all workspace central screens

}}
shouldShowThreeDotsButton={!policy?.hasMultipleTagLists}
threeDotsMenuItems={threeDotsMenuItems}
Expand Down
Loading