Skip to content

Commit cfff715

Browse files
authored
Merge pull request Expensify#89080 from software-mansion-labs/war-in/fix-native-share-back-button
fix: Expensify#88963 - fallback to split navigator's default route when there's no `existingFirstRoute`
2 parents 6df7dd9 + 2ea1e8d commit cfff715

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Log from '@libs/Log';
55
import buildTabNavigatorNestedState from '@libs/Navigation/helpers/buildTabNavigatorNestedState';
66
import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath';
77
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
8-
import {SIDEBAR_TO_SPLIT} from '@libs/Navigation/linkingConfig/RELATIONS';
8+
import {SIDEBAR_TO_SPLIT, SPLIT_TO_SIDEBAR} from '@libs/Navigation/linkingConfig/RELATIONS';
99
import type {NavigationPartialRoute} from '@libs/Navigation/types';
1010
import CONST from '@src/CONST';
1111
import NAVIGATORS from '@src/NAVIGATORS';
@@ -365,14 +365,19 @@ function handleReplaceFullscreenUnderRHP(
365365
}
366366
// Prepend the existing sidebar/root route (e.g. Inbox) to the incoming state when
367367
// it starts with a different screen, so back navigation from the new screen
368-
// lands on the sidebar.
368+
// lands on the sidebar. When the existing tab doesn't have nested
369+
// routes (e.g. cold-start through a deep link that opens straight into a modal),
370+
// fall back to the split navigator's default sidebar route so there is still
371+
// something to pop back to.
369372
let mergedNestedState = focusedTargetTab.state;
370373
const existingNestedRoutes = (r.state as PartialState<NavigationState> | undefined)?.routes;
371374
const newNestedRoutes = focusedTargetTab.state?.routes;
372375
const existingFirstRoute = existingNestedRoutes?.at(0);
373376
const newFirstRoute = newNestedRoutes?.at(0);
374-
if (existingFirstRoute && newFirstRoute && existingFirstRoute.name !== newFirstRoute.name) {
375-
const prependedRoutes = [existingFirstRoute, ...(newNestedRoutes ?? [])];
377+
const defaultSidebarRouteName = r.name in SPLIT_TO_SIDEBAR ? SPLIT_TO_SIDEBAR[r.name as keyof typeof SPLIT_TO_SIDEBAR] : undefined;
378+
const sidebarRoute: NavigationPartialRoute | undefined = existingFirstRoute ?? (defaultSidebarRouteName ? {name: defaultSidebarRouteName} : undefined);
379+
if (sidebarRoute && newFirstRoute && sidebarRoute.name !== newFirstRoute.name) {
380+
const prependedRoutes = [sidebarRoute, ...(newNestedRoutes ?? [])];
376381
mergedNestedState = {...focusedTargetTab.state, routes: prependedRoutes, index: prependedRoutes.length - 1};
377382
}
378383
return {

0 commit comments

Comments
 (0)