-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Search v1] Implement Search navigation logic #40280
Changes from 24 commits
c96e516
1e5150b
eef26cc
3c74507
a707c28
3afd0b9
2206c1d
e7de7ea
b9d88d9
a1b228a
a72d221
633d881
2d78c11
b57d456
2fcae18
18ed94f
1de5ce3
f84911b
8ea25e3
5ea4a9f
2e38d66
f724761
f28c388
1b33065
39a308a
0c538bb
3cb9dbe
faf9a69
87a4076
3b7a83d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React from 'react'; | ||
import type {CentralPaneNavigatorParamList, NavigationPartialRoute} from '@libs/Navigation/types'; | ||
|
||
const ActiveRouteContext = React.createContext(''); | ||
const ActiveRouteContext = React.createContext<NavigationPartialRoute<keyof CentralPaneNavigatorParamList> | undefined>(undefined); | ||
|
||
export default ActiveRouteContext; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,25 @@ import {createNavigatorFactory, useNavigationBuilder} from '@react-navigation/na | |
import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack'; | ||
import {StackView} from '@react-navigation/stack'; | ||
import React, {useEffect, useMemo} from 'react'; | ||
import {View} from 'react-native'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; | ||
import navigationRef from '@libs/Navigation/navigationRef'; | ||
import type {RootStackParamList, State} from '@libs/Navigation/types'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import SCREENS from '@src/SCREENS'; | ||
import CustomRouter from './CustomRouter'; | ||
import type {ResponsiveStackNavigatorProps, ResponsiveStackNavigatorRouterOptions} from './types'; | ||
|
||
type Routes = StackNavigationState<ParamListBase>['routes']; | ||
function reduceReportRoutes(routes: Routes): Routes { | ||
function reduceCentralPaneRoutes(routes: Routes): Routes { | ||
const result: Routes = []; | ||
let count = 0; | ||
const reverseRoutes = [...routes].reverse(); | ||
|
||
reverseRoutes.forEach((route) => { | ||
if (route.name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR) { | ||
// Remove all report routes except the last 3. This will improve performance. | ||
// Remove all central pane routes except the last 3. This will improve performance. | ||
if (count < 3) { | ||
result.push(route); | ||
count++; | ||
|
@@ -52,15 +56,34 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) { | |
navigationRef.resetRoot(navigationRef.getRootState()); | ||
}, [isSmallScreenWidth]); | ||
|
||
const stateToRender = useMemo(() => { | ||
const result = reduceReportRoutes(state.routes); | ||
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; | ||
|
||
const firstRoute = routes[0]; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add comment here
|
||
if (isSmallScreenWidth && isLastRouteSearchRoute) { | ||
return { | ||
stateToRender: { | ||
...state, | ||
index: 0, | ||
routes: [firstRoute], | ||
}, | ||
searchRoute: lastRoute, | ||
}; | ||
} | ||
|
||
return { | ||
...state, | ||
index: result.length - 1, | ||
routes: [...result], | ||
stateToRender: { | ||
...state, | ||
index: routes.length - 1, | ||
routes: [...routes], | ||
}, | ||
searchRoute: undefined, | ||
}; | ||
}, [state]); | ||
}, [state, isSmallScreenWidth]); | ||
|
||
return ( | ||
<NavigationContent> | ||
|
@@ -71,6 +94,7 @@ function ResponsiveStackNavigator(props: ResponsiveStackNavigatorProps) { | |
descriptors={descriptors} | ||
navigation={navigation} | ||
/> | ||
{searchRoute && <View style={{display: 'none'}}>{descriptors[searchRoute.key].render()}</View>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's extract this style |
||
</NavigationContent> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was only for the POC with onyxTab I assume