Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out search central pane in small screen #43628

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ParamListBase, StackActionHelpers, StackNavigationState} from '@react-navigation/native';
import type {ParamListBase, RouteProp, StackActionHelpers, StackNavigationState} from '@react-navigation/native';
import {createNavigatorFactory, useNavigationBuilder} from '@react-navigation/native';
import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack';
import {StackView} from '@react-navigation/stack';
Expand Down Expand Up @@ -61,20 +61,20 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) {
const {stateToRender, searchRoute} = useMemo(() => {
const routes = reduceCentralPaneRoutes(state.routes);

const lastRoute = routes[routes.length - 1];
const isLastRouteSearchRoute = getTopmostCentralPaneRoute({routes: [lastRoute]} as State<RootStackParamList>)?.name === SCREENS.SEARCH.CENTRAL_PANE;
// On narrow layout, if we are on /search route we want to hide the search central pane route.
if (isSmallScreenWidth) {
const isSearchCentralPane = (route: RouteProp<ParamListBase>) => getTopmostCentralPaneRoute({routes: [route]} as State<RootStackParamList>)?.name === SCREENS.SEARCH.CENTRAL_PANE;

const firstRoute = routes[0];

// On narrow layout, if we are on /search route we want to hide all central pane routes and show only the bottom tab navigator.
if (isSmallScreenWidth && isLastRouteSearchRoute) {
const lastRoute = routes[routes.length - 1];
const lastSearchCentralPane = isSearchCentralPane(lastRoute) ? lastRoute : undefined;
const filteredRoutes = routes.filter((route) => !isSearchCentralPane(route));
return {
stateToRender: {
...state,
index: 0,
routes: [firstRoute],
index: filteredRoutes.length - 1,
routes: filteredRoutes,
},
searchRoute: lastRoute,
searchRoute: lastSearchCentralPane,
};
}

Expand Down
Loading