@@ -1198,39 +1198,22 @@ function removePreInsertedFullscreenIfNeeded() {
11981198 return ;
11991199 }
12001200
1201- // RHP already dismissed. For the tab-switch path, jump back to the original tab.
1202- // For the push path, pop the pre-inserted route directly.
1201+ // RHP already dismissed. Restore the entire TAB_NAVIGATOR route from the snapshot so both the focused tab
1202+ // and every tab's nested state are put back. A bare jumpTo only restores focus, while resetting the active
1203+ // nested tab router can discard the inactive tabs that were also present in the snapshot.
12031204 const originalTabRoute = getPreInsertedOriginalTabRoute ( ) ;
12041205 if ( originalTabRoute ) {
12051206 clearPreInsertedOriginalTabRoute ( ) ;
1206- const originalTabState = originalTabRoute . state ;
1207- const originalFocusedTabIndex = originalTabState ?. index ?? 0 ;
1208- const originalTabName = originalTabState ?. routes ?. [ originalFocusedTabIndex ] ?. name ;
1209- if ( originalTabName ) {
1210- requestAnimationFrame ( ( ) => {
1211- const currentState = navigationRef . getRootState ( ) ;
1212- const tabNavRoute = currentState ?. routes . findLast ( ( r ) => r . name === NAVIGATORS . TAB_NAVIGATOR ) ;
1213- if ( ! tabNavRoute ?. state ?. key ) {
1214- return ;
1215- }
1216- // A same-tab pre-insert (e.g. a report pre-inserted while another report of the same split navigator was
1217- // visible) rewrote the focused tab's inner state in place, so jumping to the tab name would be a no-op
1218- // that leaves the pre-inserted screen visible. Reset the tab navigator to the saved original route state
1219- // so the screen the user started on comes back.
1220- const focusedTabName = tabNavRoute . state . routes ?. at ( tabNavRoute . state . index ?? 0 ) ?. name ;
1221- if ( focusedTabName === originalTabName && originalTabState ) {
1222- navigationRef . current ?. dispatch ( {
1223- ...CommonActions . reset ( originalTabState ) ,
1224- target : tabNavRoute . state . key ,
1225- } ) ;
1226- return ;
1227- }
1228- navigationRef . current ?. dispatch ( {
1229- ...TabActions . jumpTo ( originalTabName ) ,
1230- target : tabNavRoute . state . key ,
1231- } ) ;
1232- } ) ;
1233- }
1207+ requestAnimationFrame ( ( ) => {
1208+ const currentState = navigationRef . getRootState ( ) ;
1209+ const tabNavIndex = currentState ?. routes . findLastIndex ( ( r ) => r . name === NAVIGATORS . TAB_NAVIGATOR ) ?? - 1 ;
1210+ if ( ! currentState || tabNavIndex < 0 ) {
1211+ return ;
1212+ }
1213+ const newRoutes = [ ...currentState . routes . slice ( 0 , tabNavIndex ) , originalTabRoute , ...currentState . routes . slice ( tabNavIndex + 1 ) ] ;
1214+ const clampedIndex = currentState . index >= newRoutes . length ? newRoutes . length - 1 : currentState . index ;
1215+ navigationRef . resetRoot ( { ...currentState , routes : newRoutes , index : clampedIndex } ) ;
1216+ } ) ;
12341217 return ;
12351218 }
12361219
0 commit comments