Skip to content

Commit

Permalink
Remove Navigation.popToTop and add shouldPopToTop to GoBackOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Dec 20, 2024
1 parent 99fc247 commit 17759f4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,17 @@ type GoBackOptions = {
* In that case we want to goUp to a country picker with any params so we don't compare them.
*/
compareParams?: boolean;

/**
* Specifies whether goBack should pop to top when invoked.
* Additionaly, to execute popToTop, set the value of the global variable ShouldPopAllStateOnUP to true using the setShouldPopAllStateOnUP function.
*/
shouldPopToTop?: boolean;
};

const defaultGoBackOptions: Required<GoBackOptions> = {
compareParams: true,
shouldPopToTop: false,
};

/**
Expand Down Expand Up @@ -298,6 +305,14 @@ function goBack(fallbackRoute?: Route, options?: GoBackOptions) {
return;
}

if (options?.shouldPopToTop) {
if (shouldPopAllStateOnUP) {
shouldPopAllStateOnUP = false;
navigationRef.current?.dispatch(StackActions.popToTop());
return;
}
}

if (fallbackRoute) {
goUp(fallbackRoute, options);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string, shouldPopToTop
// @TODO: Check if this method works the same as on the main branch
if (shouldPopToTop) {
Navigation.setShouldPopAllStateOnUP(true);
Navigation.popToTop();
Navigation.goBack(undefined, {shouldPopToTop: true});
} else {
Navigation.goBack();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/navigateAfterJoinRequest/index.desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ROUTES from '@src/ROUTES';

const navigateAfterJoinRequest = () => {
// @TODO: Check if this method works the same as on the main branch
Navigation.popToTop();
Navigation.goBack(undefined, {shouldPopToTop: true});
if (getIsSmallScreenWidth()) {
Navigation.navigate(ROUTES.SETTINGS);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/navigateAfterJoinRequest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ROUTES from '@src/ROUTES';

const navigateAfterJoinRequest = () => {
// @TODO: Check if this method works the same as on the main branch
Navigation.popToTop();
Navigation.goBack(undefined, {shouldPopToTop: true});
Navigation.navigate(ROUTES.SETTINGS);
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
};
Expand Down
2 changes: 1 addition & 1 deletion src/libs/navigateAfterJoinRequest/index.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ROUTES from '@src/ROUTES';

const navigateAfterJoinRequest = () => {
// @TODO: Check if this method works the same as on the main branch
Navigation.popToTop();
Navigation.goBack(undefined, {shouldPopToTop: true});
if (getIsSmallScreenWidth()) {
Navigation.navigate(ROUTES.SETTINGS);
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
return;
}
// @TODO: Handle popToTop here
Navigation.goBack(ROUTES.HOME);
Navigation.goBack(ROUTES.HOME, {shouldPopToTop: true});
}, [isInNarrowPaneModal]);

let headerView = (
Expand Down Expand Up @@ -609,7 +609,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
if (Navigation.getTopmostReportId() === prevOnyxReportID) {
Navigation.setShouldPopAllStateOnUP(true);
// @TODO: Check if this method works the same as on the main branch
Navigation.popToTop();
Navigation.goBack(undefined, {shouldPopToTop: true});
}
if (prevReport?.parentReportID) {
// Prevent navigation to the IOU/Expense Report if it is pending deletion.
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceJoinUserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function WorkspaceJoinUserPage({route, policy}: WorkspaceJoinUserPageProps) {
Navigation.isNavigationReady().then(() => {
// @TODO: Check if this method works the same as on the main branch
// NOTE: It probably doesn't need any params. When this method is called, shouldPopAllStateOnUP is always false
Navigation.popToTop();
Navigation.goBack(undefined, {shouldPopToTop: true});
Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID ?? '-1'));
});
return;
Expand Down

0 comments on commit 17759f4

Please sign in to comment.