|
1 |
| -import type {ParamListBase, StackActionHelpers, StackNavigationState} from '@react-navigation/native'; |
| 1 | +import type {ParamListBase, RouteProp, StackActionHelpers, StackNavigationState} from '@react-navigation/native'; |
2 | 2 | import {createNavigatorFactory, useNavigationBuilder} from '@react-navigation/native';
|
3 | 3 | import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack';
|
4 | 4 | import {StackView} from '@react-navigation/stack';
|
@@ -61,23 +61,23 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) {
|
61 | 61 |
|
62 | 62 | // On narrow layout, if we are on /search route we want to hide the search central pane route.
|
63 | 63 | if (isSmallScreenWidth) {
|
64 |
| - const searchCentralPaneIndex = routes.findIndex((route) => { |
65 |
| - if (route.name !== NAVIGATORS.CENTRAL_PANE_NAVIGATOR) { |
66 |
| - return false; |
| 64 | + let lastSearchCentralPane: RouteProp<ParamListBase> | undefined; |
| 65 | + const filteredRoutes = routes.filter((route) => { |
| 66 | + const isSearchCentralPane = |
| 67 | + route.name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR && |
| 68 | + ((!!route.params && 'screen' in route.params && route.params.screen === SCREENS.SEARCH.CENTRAL_PANE) || route.state?.routes.at(-1)?.name === SCREENS.SEARCH.CENTRAL_PANE); |
| 69 | + if (isSearchCentralPane) { |
| 70 | + lastSearchCentralPane = route; |
67 | 71 | }
|
68 |
| - |
69 |
| - return ( |
70 |
| - (!!route.params && 'screen' in route.params && route.params.screen === SCREENS.SEARCH.CENTRAL_PANE) || route.state?.routes.at(-1)?.name === SCREENS.SEARCH.CENTRAL_PANE |
71 |
| - ); |
| 72 | + return !isSearchCentralPane; |
72 | 73 | });
|
73 |
| - const filteredRoutes = searchCentralPaneIndex !== -1 ? [...routes.slice(0, searchCentralPaneIndex), ...routes.slice(searchCentralPaneIndex + 1)] : [...routes]; |
74 | 74 | return {
|
75 | 75 | stateToRender: {
|
76 | 76 | ...state,
|
77 | 77 | index: filteredRoutes.length - 1,
|
78 | 78 | routes: filteredRoutes,
|
79 | 79 | },
|
80 |
| - searchRoute: routes[searchCentralPaneIndex], |
| 80 | + searchRoute: lastSearchCentralPane, |
81 | 81 | };
|
82 | 82 | }
|
83 | 83 |
|
|
0 commit comments