Skip to content

Commit 899b8c7

Browse files
authored
Merge pull request #46360 from bernhardoj/fix/46063-page-blink-when-categorizing-expense
Fix page blinks after selecting a category during categorization
2 parents 9a3d72a + 3ea0148 commit 899b8c7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/libs/Navigation/Navigation.ts

+20
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,25 @@ function goBack(fallbackRoute?: Route, shouldEnforceFallback = false, shouldPopT
266266
navigationRef.current.goBack();
267267
}
268268

269+
/**
270+
* Close the current screen and navigate to the route.
271+
* If the current screen is the first screen in the navigator, we force using the fallback route to replace the current screen.
272+
* It's useful in a case where we want to close an RHP and navigate to another RHP to prevent any blink effect.
273+
*/
274+
function closeAndNavigate(route: Route) {
275+
if (!navigationRef.current) {
276+
return;
277+
}
278+
279+
const isFirstRouteInNavigator = !getActiveRouteIndex(navigationRef.current.getState());
280+
if (isFirstRouteInNavigator) {
281+
goBack(route, true);
282+
return;
283+
}
284+
goBack();
285+
navigate(route);
286+
}
287+
269288
/**
270289
* Reset the navigation state to Home page
271290
*/
@@ -396,6 +415,7 @@ export default {
396415
isActiveRoute,
397416
getActiveRoute,
398417
getActiveRouteWithoutParams,
418+
closeAndNavigate,
399419
goBack,
400420
isNavigationReady,
401421
setIsNavigationReady,

src/pages/iou/request/step/IOURequestStepCategory.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ function IOURequestStepCategory({
145145
IOU.setMoneyRequestCategory(transactionID, updatedCategory);
146146

147147
if (action === CONST.IOU.ACTION.CATEGORIZE) {
148-
Navigation.goBack();
149-
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1'));
148+
Navigation.closeAndNavigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1'));
150149
return;
151150
}
152151

0 commit comments

Comments
 (0)