|
1 | | -import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigationState} from '@react-navigation/native'; |
2 | | -import {StackActions} from '@react-navigation/native'; |
| 1 | +import type {RouterConfigOptions, StackActionType, StackNavigationState} from '@react-navigation/native'; |
| 2 | +import {CommonActions, StackActions} from '@react-navigation/native'; |
3 | 3 | import type {ParamListBase, Router} from '@react-navigation/routers'; |
4 | 4 | import SCREENS_WITH_NAVIGATION_TAB_BAR from '@components/Navigation/TopLevelNavigationTabBar/SCREENS_WITH_NAVIGATION_TAB_BAR'; |
5 | 5 | import getIsNarrowLayout from '@libs/getIsNarrowLayout'; |
@@ -152,17 +152,26 @@ function handleDismissModalAction( |
152 | 152 | return null; |
153 | 153 | } |
154 | 154 |
|
155 | | - let newAction = StackActions.pop(); |
156 | | - |
157 | | - if (lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR) { |
| 155 | + if (lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && lastRoute?.state) { |
158 | 156 | const rhpRoutes = lastRoute?.state?.routes; |
159 | 157 | // This handles closing the modal when wide rhp is visible |
160 | | - if (rhpRoutes?.at(0)?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT && rhpRoutes?.length > 1) { |
161 | | - newAction = {...StackActions.popToTop(), target: lastRoute.state?.key}; |
162 | | - return; |
| 158 | + const wideRhpIndex = rhpRoutes.findLastIndex((rhpRoute) => rhpRoute.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT); |
| 159 | + if (wideRhpIndex > -1 && wideRhpIndex !== rhpRoutes.length - 1) { |
| 160 | + const modifiedRhp = { |
| 161 | + ...lastRoute, |
| 162 | + state: { |
| 163 | + ...lastRoute.state, |
| 164 | + index: wideRhpIndex, |
| 165 | + routes: lastRoute.state.routes.slice(0, wideRhpIndex + 1), |
| 166 | + history: lastRoute.state.history?.slice(0, wideRhpIndex + 1), |
| 167 | + }, |
| 168 | + }; |
| 169 | + const modifiedState = {...state, routes: [...state.routes.slice(0, -1), modifiedRhp]}; |
| 170 | + const action = CommonActions.reset(modifiedState); |
| 171 | + return stackRouter.getStateForAction(state, action, configOptions); |
163 | 172 | } |
164 | 173 | } |
165 | | - |
| 174 | + const newAction = StackActions.pop(); |
166 | 175 | return stackRouter.getStateForAction(state, newAction, configOptions); |
167 | 176 | } |
168 | 177 |
|
|
0 commit comments