Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
import type {CustomStateHookProps} from '@libs/Navigation/PlatformStackNavigation/types';

// This is an optimization to keep mounted only last few screens in the stack.
// We keep the last full screen and the one before it to avoid unmounting persistent screens
// (like ReportsSplitNavigator) which contain heavy component trees (e.g. LHN with thousands of items).
export default function useCustomRootStackNavigatorState({state}: CustomStateHookProps) {
const lastSplitIndex = state.routes.findLastIndex((route) => isFullScreenName(route.name));
const indexToSlice = Math.max(0, lastSplitIndex - 1);
let indexToSlice = Math.max(0, lastSplitIndex);
const hasPrevRoute = lastSplitIndex > 0;
const isPrevFullScreen = isFullScreenName(state.routes.at(lastSplitIndex - 1)?.name);

// If the route before the last full screen is e.g. RHP, we should leave it in the rendered routes,
// as there may be display issues (blank screen) when navigating back and recreating that route to render.
if (hasPrevRoute && !isPrevFullScreen) {
indexToSlice = lastSplitIndex - 1;
}
const routesToRender = state.routes.slice(indexToSlice, state.routes.length);
return {...state, routes: routesToRender, index: routesToRender.length - 1};
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ function usePreloadFullScreenNavigators() {
}
hasPreloadedRef.current = true;
setTimeout(() => {
const currentRoutes = navigation.getState().routes;
for (const tabName of TABS_TO_PRELOAD) {
// Don't preload the current tab
const isCurrentTab = TAB_TO_FULLSCREEN[tabName].includes(route.name as FullScreenName);
Expand All @@ -148,13 +147,6 @@ function usePreloadFullScreenNavigators() {
continue;
}

// Don't preload tabs whose navigator is already in the regular routes stack
const isRouteInStack = currentRoutes.some((r) => TAB_TO_FULLSCREEN[tabName].includes(r.name as FullScreenName));

if (isRouteInStack) {
continue;
}

// Preload everything else
preloadTab(tabName, navigation, subscriptionPlan);
}
Expand Down
Loading