-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Simplify the RootNavigator structure #42582
Merged
mountiny
merged 34 commits into
Expensify:main
from
software-mansion-labs:nav/flatten-central-pane
Jun 25, 2024
Merged
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
fb87e2e
Move settings to AuthScreens
WojtekBoman 1411be4
Remove CentralPane
WojtekBoman aa779db
Add adjustments for new nav structure
WojtekBoman 87ccd3e
Add CENTRAL_PANE_SCREENS
WojtekBoman a381924
Rename CentralPaneScreen to CentralPaneName
WojtekBoman da6c4fb
Adjust switchPolicyID to new nav structure
WojtekBoman 43d4ca0
Remove getTopmostRoute
WojtekBoman 7eef033
Add withPrepareCentralPaneScreen
WojtekBoman 5410620
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman eb2473d
Add ts fixes
WojtekBoman 118c049
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman e87c30a
AuthScreens and CENTRAL_PANE_SCREENS cleanup
WojtekBoman ca681c7
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman c06c5dc
Fix storybook tests
WojtekBoman 09ba271
Add docs for withPrepareCentralPaneScreen
WojtekBoman 28c7a3f
Rename CentralPaneNameOptions
WojtekBoman 99d5523
fix tests
adamgrzybowski a7a288a
Merge branch 'main' into nav/flatten-central-pane
adamgrzybowski 64d29a7
Merge branch 'main' into nav/flatten-central-pane
adamgrzybowski 19e05dd
fix types
adamgrzybowski 3fc2ede
Merge branch 'main' into nav/flatten-central-pane
adamgrzybowski 5a133a7
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman 9bc1bec
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman be4d349
Fix types for central pane screens
WojtekBoman baaf214
fix central pane blinking on android
adamgrzybowski e92622a
fix accessing route params object in report screen
adamgrzybowski 0698b3f
Merge branch 'main' into nav/flatten-central-pane
adamgrzybowski 73721e3
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman 9d137bd
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman 70254e5
Cleaunp flatten central pane code
WojtekBoman c905a4c
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman 38c21a0
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman 0efb9f0
Merge branch 'main' into nav/flatten-central-pane
WojtekBoman becff51
Fix lint in switchPolicyID
WojtekBoman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,12 @@ import ROUTES from '@src/ROUTES'; | |
import SCREENS from '@src/SCREENS'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails'; | ||
import {CENTRAL_PANE_SCREENS} from './CENTRAL_PANE_SCREENS'; | ||
import type {CentralPaneName} from './CENTRAL_PANE_SCREENS'; | ||
import createCustomStackNavigator from './createCustomStackNavigator'; | ||
import defaultScreenOptions from './defaultScreenOptions'; | ||
import getRootNavigatorScreenOptions from './getRootNavigatorScreenOptions'; | ||
import BottomTabNavigator from './Navigators/BottomTabNavigator'; | ||
import CentralPaneNavigator from './Navigators/CentralPaneNavigator'; | ||
import FeatureTrainingModalNavigator from './Navigators/FeatureTrainingModalNavigator'; | ||
import FullScreenNavigator from './Navigators/FullScreenNavigator'; | ||
import LeftModalNavigator from './Navigators/LeftModalNavigator'; | ||
|
@@ -157,6 +158,9 @@ const modalScreenListeners = { | |
}, | ||
}; | ||
|
||
const url = getCurrentUrl(); | ||
const openOnAdminRoom = url ? new URL(url).searchParams.get('openOnAdminRoom') : undefined; | ||
|
||
function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDAppliedToClient}: AuthScreensProps) { | ||
const styles = useThemeStyles(); | ||
const StyleUtils = useStyleUtils(); | ||
|
@@ -273,20 +277,28 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie | |
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const CentralPaneNameOptions = { | ||
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. I am wondering if this name is good for this structure |
||
headerShown: false, | ||
title: 'New Expensify', | ||
|
||
// Prevent unnecessary scrolling | ||
cardStyle: styles.cardStyleNavigator, | ||
}; | ||
|
||
// @TODO: Check whether CENTRAL_PANE_SCREENS should be wrapped by FreezeWrapper on native platforms | ||
|
||
return ( | ||
<OptionsListContextProvider> | ||
<View style={styles.rootNavigatorContainerStyles(isSmallScreenWidth)}> | ||
<RootStack.Navigator isSmallScreenWidth={isSmallScreenWidth}> | ||
<RootStack.Navigator | ||
screenOptions={screenOptions.centralPaneNavigator} | ||
isSmallScreenWidth={isSmallScreenWidth} | ||
> | ||
<RootStack.Screen | ||
name={NAVIGATORS.BOTTOM_TAB_NAVIGATOR} | ||
options={screenOptions.bottomTab} | ||
component={BottomTabNavigator} | ||
/> | ||
<RootStack.Screen | ||
name={NAVIGATORS.CENTRAL_PANE_NAVIGATOR} | ||
options={screenOptions.centralPaneNavigator} | ||
component={CentralPaneNavigator} | ||
/> | ||
<RootStack.Screen | ||
name={SCREENS.VALIDATE_LOGIN} | ||
options={{ | ||
|
@@ -408,6 +420,15 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie | |
options={defaultScreenOptions} | ||
component={ConnectionCompletePage} | ||
/> | ||
{Object.entries(CENTRAL_PANE_SCREENS).map(([screenName, componentGetter]) => ( | ||
<RootStack.Screen | ||
key={screenName} | ||
name={screenName as CentralPaneName} | ||
initialParams={{openOnAdminRoom: (screenName === SCREENS.REPORT && openOnAdminRoom === 'true') || undefined}} | ||
getComponent={componentGetter} | ||
options={CentralPaneNameOptions} | ||
/> | ||
))} | ||
</RootStack.Navigator> | ||
</View> | ||
</OptionsListContextProvider> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type {AuthScreensParamList} from '@libs/Navigation/types'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
type Screens = Partial<Record<keyof AuthScreensParamList, () => React.ComponentType>>; | ||
|
||
const CENTRAL_PANE_SCREENS = { | ||
[SCREENS.SETTINGS.WORKSPACES]: () => require('../../../pages/workspace/WorkspacesListPage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.PREFERENCES.ROOT]: () => require('../../../pages/settings/Preferences/PreferencesPage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.SECURITY]: () => require('../../../pages/settings/Security/SecuritySettingsPage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.PROFILE.ROOT]: () => require('../../../pages/settings/Profile/ProfilePage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.WALLET.ROOT]: () => require('../../../pages/settings/Wallet/WalletPage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.ABOUT]: () => require('../../../pages/settings/AboutPage/AboutPage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.TROUBLESHOOT]: () => require('../../../pages/settings/Troubleshoot/TroubleshootPage').default as React.ComponentType, | ||
[SCREENS.SETTINGS.SAVE_THE_WORLD]: () => require('../../../pages/TeachersUnite/SaveTheWorldPage').default as React.ComponentType, | ||
[SCREENS.SEARCH.CENTRAL_PANE]: () => require('../../../pages/Search/SearchPage').default as React.ComponentType, | ||
[SCREENS.REPORT]: () => require('./ReportScreenWrapper').default as React.ComponentType, | ||
} satisfies Screens; | ||
|
||
const CENTRAL_PANE_SCREEN_NAMES = Object.keys(CENTRAL_PANE_SCREENS); | ||
|
||
type CentralPaneName = keyof typeof CENTRAL_PANE_SCREENS; | ||
|
||
export type {CentralPaneName}; | ||
|
||
export {CENTRAL_PANE_SCREENS, CENTRAL_PANE_SCREEN_NAMES}; |
4 changes: 2 additions & 2 deletions
4
src/libs/Navigation/AppNavigator/Navigators/ActiveRouteContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
import type {CentralPaneNavigatorParamList, NavigationPartialRoute} from '@libs/Navigation/types'; | ||
import type {AuthScreensParamList, NavigationPartialRoute} from '@libs/Navigation/types'; | ||
|
||
const ActiveRouteContext = React.createContext<NavigationPartialRoute<keyof CentralPaneNavigatorParamList> | undefined>(undefined); | ||
const ActiveRouteContext = React.createContext<NavigationPartialRoute<keyof AuthScreensParamList> | undefined>(undefined); | ||
|
||
export default ActiveRouteContext; |
3 changes: 2 additions & 1 deletion
3
src/libs/Navigation/AppNavigator/Navigators/BottomTabNavigator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
...libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.tsx
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/index.native.tsx
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it more correct if we use type
CentralPaneScreensParamList
here?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.
CentralPaneScreensParamList
is a subset ofAuthScreens
and it has been added to increase code readability and handle types correctly in thegetCentralPaneScreenInitialParams
function. For screens, I believe we should rely on the main set of screens.cc: @adamgrzybowski
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.
Yeah, the navigation object should be typed with all the screens from AuthNavigator | RootStack