From a14b4ddb9b2fe687dd8d3fc6511a5dd6a8d5c837 Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:39:52 +0100 Subject: [PATCH] Merge pull request #57320 from Expensify/revert-57110-split/nav-without-sidebar [CP Staging] Revert "Adjust adaptStateIfNecessary to push a split navigator without a sidebar screen" (cherry picked from commit 819310f5d43269d7d02a69ac63ecf64ba1c800ce) (CP triggered by mountiny) --- .../AppNavigator/createSplitNavigator/SplitRouter.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts index e2699ef81488..f4ecfe3700f1 100644 --- a/src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts +++ b/src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts @@ -26,7 +26,6 @@ function getRoutePolicyID(route: NavigationPartialRoute): string | undefined { function adaptStateIfNecessary({state, options: {sidebarScreen, defaultCentralScreen, parentRoute}}: AdaptStateIfNecessaryArgs) { const isNarrowLayout = getIsNarrowLayout(); - const rootState = navigationRef.getRootState(); const lastRoute = state.routes.at(-1) as NavigationPartialRoute; const routePolicyID = getRoutePolicyID(lastRoute); @@ -38,14 +37,10 @@ function adaptStateIfNecessary({state, options: {sidebarScreen, defaultCentralSc } } - // When initializing the app on a small screen with the center screen as the initial screen, the sidebar must also be split to allow users to swipe back. - const isInitialRoute = !rootState || rootState.routes.length === 1; - const shouldSplitHaveSidebar = isInitialRoute || !isNarrowLayout; - // If the screen is wide, there should be at least two screens inside: // - sidebarScreen to cover left pane. // - defaultCentralScreen to cover central pane. - if (!isAtLeastOneInState(state, sidebarScreen) && shouldSplitHaveSidebar) { + if (!isAtLeastOneInState(state, sidebarScreen)) { const paramsFromRoute = getParamsFromRoute(sidebarScreen); const copiedParams = pick(lastRoute?.params, paramsFromRoute); @@ -70,6 +65,8 @@ function adaptStateIfNecessary({state, options: {sidebarScreen, defaultCentralSc // - defaultCentralScreen to cover central pane. if (!isNarrowLayout) { if (state.routes.length === 1 && state.routes[0].name === sidebarScreen) { + const rootState = navigationRef.getRootState(); + const previousSameNavigator = rootState?.routes.filter((route) => route.name === parentRoute.name).at(-2); // If we have optimization for not rendering all split navigators, then last selected option may not be in the state. In this case state has to be read from the preserved state.