From 29ea20fd2124b4ae972723c7b314208010fd55ae Mon Sep 17 00:00:00 2001 From: sepeterson <10458078+sepeterson@users.noreply.github.com> Date: Fri, 13 Feb 2026 16:42:52 -0600 Subject: [PATCH] MOB-1190: preserve state of other tabs --- .../CustomTabBarContainer.tsx | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/navigation/BottomTabNavigator/CustomTabBarContainer.tsx b/src/navigation/BottomTabNavigator/CustomTabBarContainer.tsx index 733eb5547..8d39a4f00 100644 --- a/src/navigation/BottomTabNavigator/CustomTabBarContainer.tsx +++ b/src/navigation/BottomTabNavigator/CustomTabBarContainer.tsx @@ -1,4 +1,5 @@ import type { BottomTabBarProps } from "@react-navigation/bottom-tabs"; +import type { NavigationRoute, ParamListBase } from "@react-navigation/native"; import { CommonActions } from "@react-navigation/native"; import { SCREEN_NAME_MENU, @@ -53,6 +54,22 @@ const CustomTabBarContainer: React.FC = ( { navigation, state } ) => { }; const resetStack = useCallback( ( tabName: TabName, screenName: ScreenName ) => { + const navState = navigation.getState( ); + // copy existing stack routes so we don't lose state for tabs we're not resetting + const newStacks: Partial>[] + = navState.routes.slice(); + const replaceIndex = newStacks.findIndex( r => r.name === tabName ); + // add reset stack + newStacks.splice( replaceIndex, 1, { + name: tabName, + state: { + index: 0, + routes: [ + { name: screenName }, + ], + }, + } ); + navigation.dispatch( CommonActions.reset( { index: 0, @@ -60,17 +77,8 @@ const CustomTabBarContainer: React.FC = ( { navigation, state } ) => { { name: "TabNavigator", state: { - routes: [ - { - name: tabName, - state: { - index: 0, - routes: [ - { name: screenName }, - ], - }, - }, - ], + index: navState.index, + routes: newStacks, }, }, ],