diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 10301e0a99b3..4bd86503fd2b 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -266,6 +266,25 @@ function goBack(fallbackRoute?: Route, shouldEnforceFallback = false, shouldPopT navigationRef.current.goBack(); } +/** + * Close the current screen and navigate to the route. + * If the current screen is the first screen in the navigator, we force using the fallback route to replace the current screen. + * It's useful in a case where we want to close an RHP and navigate to another RHP to prevent any blink effect. + */ +function closeAndNavigate(route: Route) { + if (!navigationRef.current) { + return; + } + + const isFirstRouteInNavigator = !getActiveRouteIndex(navigationRef.current.getState()); + if (isFirstRouteInNavigator) { + goBack(route, true); + return; + } + goBack(); + navigate(route); +} + /** * Reset the navigation state to Home page */ @@ -396,6 +415,7 @@ export default { isActiveRoute, getActiveRoute, getActiveRouteWithoutParams, + closeAndNavigate, goBack, isNavigationReady, setIsNavigationReady, diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index a3b05e06f274..7130b8c86079 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -145,8 +145,7 @@ function IOURequestStepCategory({ IOU.setMoneyRequestCategory(transactionID, updatedCategory); if (action === CONST.IOU.ACTION.CATEGORIZE) { - Navigation.goBack(); - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1')); + Navigation.closeAndNavigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1')); return; }