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 1 commit
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
Expand Up @@ -6,9 +6,9 @@
import {View} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';

Check failure on line 9 in src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'getTopmostCentralPaneRoute' is defined but never used
import navigationRef from '@libs/Navigation/navigationRef';
import type {RootStackParamList, State} from '@libs/Navigation/types';

Check failure on line 11 in src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'RootStackParamList' is defined but never used

Check failure on line 11 in src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'State' is defined but never used
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';
import CustomRouter from './CustomRouter';
Expand Down Expand Up @@ -61,20 +61,23 @@
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 searchCentralPaneIndex = routes.findIndex((route) => {
if (route.name !== NAVIGATORS.CENTRAL_PANE_NAVIGATOR) {
return false;
}

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) {
return (route.params && 'screen' in route.params && route.params.screen === SCREENS.SEARCH.CENTRAL_PANE) || route.state?.routes.at(-1)?.name === SCREENS.SEARCH.CENTRAL_PANE;

Check failure on line 71 in src/libs/Navigation/AppNavigator/createCustomStackNavigator/index.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
});
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const filteredRoutes = searchCentralPaneIndex !== -1 ? [...routes.slice(0, searchCentralPaneIndex), ...routes.slice(searchCentralPaneIndex + 1)] : [...routes];
return {
stateToRender: {
...state,
index: 0,
routes: [firstRoute],
index: filteredRoutes.length - 1,
routes: filteredRoutes,
},
searchRoute: lastRoute,
searchRoute: routes[searchCentralPaneIndex],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luacmartins The reason I don't use filter is the searchRoute here expects that we pass the found search central pane route, so I need the found index of the route. The searchRoute is being used here

{searchRoute && <View style={styles.dNone}>{descriptors[searchRoute.key].render()}</View>}

but I can't see any difference though with or without searchRoute. Maybe we can ask someone from SWM to check this too. If we can safely remove it, then we can use filter.

};
}

Expand Down
Loading