Skip to content

Commit d2342db

Browse files
committed
filter out all search central pane
1 parent 6ba3cb8 commit d2342db

File tree

1 file changed

+10
-10
lines changed
  • src/libs/Navigation/AppNavigator/createCustomStackNavigator

1 file changed

+10
-10
lines changed

src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {ParamListBase, StackActionHelpers, StackNavigationState} from '@react-navigation/native';
1+
import type {ParamListBase, RouteProp, StackActionHelpers, StackNavigationState} from '@react-navigation/native';
22
import {createNavigatorFactory, useNavigationBuilder} from '@react-navigation/native';
33
import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack';
44
import {StackView} from '@react-navigation/stack';
@@ -61,23 +61,23 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) {
6161

6262
// On narrow layout, if we are on /search route we want to hide the search central pane route.
6363
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;
6771
}
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;
7273
});
73-
const filteredRoutes = searchCentralPaneIndex !== -1 ? [...routes.slice(0, searchCentralPaneIndex), ...routes.slice(searchCentralPaneIndex + 1)] : [...routes];
7474
return {
7575
stateToRender: {
7676
...state,
7777
index: filteredRoutes.length - 1,
7878
routes: filteredRoutes,
7979
},
80-
searchRoute: routes[searchCentralPaneIndex],
80+
searchRoute: lastSearchCentralPane,
8181
};
8282
}
8383

0 commit comments

Comments
 (0)