Skip to content

Commit

Permalink
Merge pull request #57320 from Expensify/revert-57110-split/nav-witho…
Browse files Browse the repository at this point in the history
…ut-sidebar

[CP Staging] Revert "Adjust adaptStateIfNecessary to push a split navigator without a sidebar screen"

(cherry picked from commit 819310f)

(CP triggered by mountiny)
  • Loading branch information
mountiny authored and OSBotify committed Feb 24, 2025
1 parent eb8c2d8 commit a14b4dd
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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.
Expand Down

0 comments on commit a14b4dd

Please sign in to comment.