Skip to content

Commit

Permalink
Make goUp private
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Nov 26, 2024
1 parent e407a8d commit 2d11aec
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 21 deletions.
16 changes: 10 additions & 6 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,26 @@ function doesRouteMatchToMinimalActionPayload(route: NavigationStateRoute | Navi
return shallowCompare(routeParams, minimalActionParams);
}

type GoUpOptions = {
type GoBackOptions = {
/** If we should compare params when searching for a route in state to go up to.
* There are situations where we want to compare params when going up e.g. goUp to a specific report.
* Sometimes we want to go up and update params of screen e.g. country picker.
* In that case we want to goUp to a country picker with any params so we don't compare them. */
compareParams?: boolean;

shouldPopToTop?: boolean;
};

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

function isRootNavigatorState(state: State): state is State<RootStackParamList> {
return state.key === navigationRef.current?.getRootState().key;
}

function goUp(fallbackRoute: Route, options?: GoUpOptions) {
function goUp(fallbackRoute: Route, options?: GoBackOptions) {
const compareParams = options?.compareParams ?? defaultGoUpOptions.compareParams;

if (!canNavigate('goBack')) {
Expand Down Expand Up @@ -253,11 +256,13 @@ function goUp(fallbackRoute: Route, options?: GoUpOptions) {
* @param fallbackRoute - Fallback route if pop/goBack action should, but is not possible within RHP
* @param shouldPopToTop - Should we navigate to LHN on back press
*/
function goBack(fallbackRoute?: Route, shouldPopToTop = false) {
function goBack(fallbackRoute?: Route, options?: GoBackOptions) {
if (!canNavigate('goBack')) {
return;
}

const shouldPopToTop = options?.shouldPopToTop ?? false;

if (shouldPopToTop) {
if (shouldPopAllStateOnUP) {
shouldPopAllStateOnUP = false;
Expand All @@ -267,7 +272,7 @@ function goBack(fallbackRoute?: Route, shouldPopToTop = false) {
}

if (fallbackRoute) {
goUp(fallbackRoute);
goUp(fallbackRoute, options);
return;
}

Expand Down Expand Up @@ -485,7 +490,6 @@ export default {
closeRHPFlow,
setNavigationActionToMicrotaskQueue,
navigateToReportWithPolicyCheck,
goUp,
};

export {navigationRef};
4 changes: 2 additions & 2 deletions src/pages/home/sidebar/BottomTabAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ function BottomTabAvatar({isCreateMenuOpen = false, isSelected = false}: BottomT
}

if (route.name === SCREENS.SETTINGS.WORKSPACES && shouldUseNarrowLayout) {
Navigation.goUp(ROUTES.SETTINGS);
Navigation.goBack(ROUTES.SETTINGS);
return;
}

if (route.name === SCREENS.WORKSPACE.INITIAL) {
Navigation.goUp(ROUTES.SETTINGS);
Navigation.goBack(ROUTES.SETTINGS);
if (shouldUseNarrowLayout) {
Navigation.navigate(ROUTES.SETTINGS, CONST.NAVIGATION.ACTION_TYPE.REPLACE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function IOURequestStepConfirmation({
// back to the participants step
if (!transaction?.participantsAutoAssigned && participantsAutoAssignedFromRoute !== 'true') {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Navigation.goUp(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action), {compareParams: false});
Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action), {compareParams: false});
return;
}
IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function CountrySelectionPage({route}: CountrySelectionPageProps) {
Navigation.goBack();
} else {
// Set compareParams to false because we want to goUp to this particular screen and update params (country).
Navigation.goUp(appendParam(backTo, 'country', option.value), {compareParams: false});
Navigation.goBack(appendParam(backTo, 'country', option.value), {compareParams: false});
}
},
[route],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function StateSelectionPage() {
Navigation.goBack();
} else {
// Set compareParams to false because we want to goUp to this particular screen and update params (state).
Navigation.goUp(appendParam(backTo, 'state', option.value), {compareParams: false});
Navigation.goBack(appendParam(backTo, 'state', option.value), {compareParams: false});
}
},
[params?.backTo],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function CardSection() {
const requestRefund = useCallback(() => {
User.requestRefund();
setIsRequestRefundModalVisible(false);
Navigation.goUp(ROUTES.HOME);
Navigation.goBack(ROUTES.HOME);
}, []);

const viewPurchases = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function PageNotFoundFallback({policyID, fullPageNotFoundViewProps, isFeatureEna
shouldForceFullScreen={shouldShowFullScreenFallback}
onBackButtonPress={() => {
if (isPolicyNotAccessible) {
Navigation.goUp(ROUTES.SETTINGS_WORKSPACES);
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);
return;
}
Navigation.goBack(policyID && !isMoneyRequest ? ROUTES.WORKSPACE_PROFILE.getRoute(policyID) : undefined);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,18 +388,18 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
>
<FullPageNotFoundView
onBackButtonPress={Navigation.dismissModal}
onLinkPress={() => Navigation.goUp(ROUTES.HOME)}
onLinkPress={() => Navigation.goBack(ROUTES.HOME)}
shouldShow={shouldShowNotFoundPage}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
>
<HeaderWithBackButton
title={policyName}
onBackButtonPress={() => {
if (route.params?.backTo) {
Navigation.goUp(ROUTES.HOME);
Navigation.goBack(ROUTES.HOME);
Navigation.isNavigationReady().then(() => Navigation.navigate(route.params?.backTo as Route));
} else {
Navigation.goUp(ROUTES.SETTINGS_WORKSPACES);
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);
}
}}
policyAvatar={policyAvatar}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspacePageWithSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ function WorkspacePageWithSections({
shouldShowOfflineIndicatorInWideScreen={shouldShowOfflineIndicatorInWideScreen && !shouldShow}
>
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goUp(ROUTES.SETTINGS_WORKSPACES)}
onLinkPress={() => Navigation.goUp(ROUTES.HOME)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onLinkPress={() => Navigation.goBack(ROUTES.HOME)}
shouldShow={shouldShow}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
shouldForceFullScreen
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function WorkspacesListPage() {
title={translate('common.workspaces')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goUp(ROUTES.SETTINGS)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
icon={Illustrations.BigRocket}
/>
<ScrollView contentContainerStyle={styles.pt3}>
Expand Down Expand Up @@ -419,7 +419,7 @@ function WorkspacesListPage() {
title={translate('common.workspaces')}
shouldShowBackButton={shouldUseNarrowLayout}
shouldDisplaySearchRouter
onBackButtonPress={() => Navigation.goUp(ROUTES.SETTINGS)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
icon={Illustrations.BigRocket}
>
{!shouldUseNarrowLayout && getHeaderButton()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function ConfirmationStep({policyID, backTo}: ConfirmationStepProps) {
if (!isSuccessful) {
return;
}
Navigation.goUp(backTo ?? ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID ?? '-1'));
Navigation.goBack(backTo ?? ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID ?? '-1'));
Card.clearIssueNewCardFlow();
}, [backTo, policyID, isSuccessful]);

Expand Down

0 comments on commit 2d11aec

Please sign in to comment.