Skip to content

Commit

Permalink
Merge pull request #43628 from bernhardoj/fix/43478-blank-when-swipin…
Browse files Browse the repository at this point in the history
…g-right-report-rhp

Filter out search central pane in small screen
  • Loading branch information
luacmartins authored Jun 17, 2024
2 parents 2c90f74 + f64d254 commit ee20f2a
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit ee20f2a

Please sign in to comment.