From 93fa76d3ba1c26c98be65ccf096bd597fbae5788 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 25 Nov 2024 10:34:54 +0100 Subject: [PATCH 01/26] Remove BOTTOM_TAB, cleanup code related to SplitNavigators --- src/NAVIGATORS.ts | 1 - src/SCREENS.ts | 1 - .../FocusTrap/BOTTOM_TAB_SCREENS.ts | 6 -- .../FocusTrapForScreen/index.web.tsx | 4 +- .../FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts | 2 - .../MentionReportRenderer/index.tsx | 11 +-- src/components/PromotedActionsBar.tsx | 9 +-- .../ScrollOffsetContextProvider.tsx | 15 ++-- .../BottomTabBar.tsx | 2 +- .../BottomTabNavigationContentWrapper.tsx | 22 ------ src/libs/Navigation/Navigation.ts | 20 ++--- .../Navigation/getTopmostCentralPaneRoute.ts | 19 ----- .../Navigation/getTopmostReportActionID.ts | 39 ---------- ...stReportId.ts => getTopmostReportParam.ts} | 15 ++-- .../Navigation/getTopmostWorkspaceRoute.ts | 28 ------- .../isSearchTopmostFullScreenRoute.ts | 2 +- .../linkingConfig/RELATIONS/index.ts | 1 + src/libs/Navigation/linkingConfig/config.ts | 2 - .../linkingConfig/customGetPathFromState.ts | 7 +- .../shouldSetScreenBlurred/index.tsx | 13 ---- src/libs/Navigation/types.ts | 10 --- src/libs/NavigationUtils.ts | 73 ++++++------------- .../FloatingActionButtonAndPopover.tsx | 14 +--- 23 files changed, 58 insertions(+), 258 deletions(-) delete mode 100644 src/components/FocusTrap/BOTTOM_TAB_SCREENS.ts delete mode 100644 src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabNavigationContentWrapper.tsx delete mode 100644 src/libs/Navigation/getTopmostCentralPaneRoute.ts delete mode 100644 src/libs/Navigation/getTopmostReportActionID.ts rename src/libs/Navigation/{getTopmostReportId.ts => getTopmostReportParam.ts} (68%) delete mode 100644 src/libs/Navigation/getTopmostWorkspaceRoute.ts delete mode 100644 src/libs/Navigation/shouldSetScreenBlurred/index.tsx diff --git a/src/NAVIGATORS.ts b/src/NAVIGATORS.ts index c6f014f24e72..7695a42a9501 100644 --- a/src/NAVIGATORS.ts +++ b/src/NAVIGATORS.ts @@ -4,7 +4,6 @@ * */ export default { CENTRAL_PANE_NAVIGATOR: 'CentralPaneNavigator', - BOTTOM_TAB_NAVIGATOR: 'BottomTabNavigator', LEFT_MODAL_NAVIGATOR: 'LeftModalNavigator', RIGHT_MODAL_NAVIGATOR: 'RightModalNavigator', ONBOARDING_MODAL_NAVIGATOR: 'OnboardingModalNavigator', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index e4fa03bf4815..4913869e3e23 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -49,7 +49,6 @@ const SCREENS = { SAVED_SEARCH_RENAME_RHP: 'Search_Saved_Search_Rename_RHP', ADVANCED_FILTERS_IN_RHP: 'Search_Advanced_Filters_In_RHP', TRANSACTION_HOLD_REASON_RHP: 'Search_Transaction_Hold_Reason_RHP', - BOTTOM_TAB: 'Search_Bottom_Tab', }, SETTINGS: { ROOT: 'Settings_Root', diff --git a/src/components/FocusTrap/BOTTOM_TAB_SCREENS.ts b/src/components/FocusTrap/BOTTOM_TAB_SCREENS.ts deleted file mode 100644 index f6a4f5ba6e83..000000000000 --- a/src/components/FocusTrap/BOTTOM_TAB_SCREENS.ts +++ /dev/null @@ -1,6 +0,0 @@ -import NAVIGATORS from '@src/NAVIGATORS'; -import SCREENS from '@src/SCREENS'; - -const BOTTOM_TAB_SCREENS = [SCREENS.HOME, SCREENS.SETTINGS.ROOT, NAVIGATORS.BOTTOM_TAB_NAVIGATOR, SCREENS.SEARCH.BOTTOM_TAB]; - -export default BOTTOM_TAB_SCREENS; diff --git a/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx b/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx index 14f14aee8c73..62a6b5d100a8 100644 --- a/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx +++ b/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx @@ -1,11 +1,11 @@ import {useIsFocused, useRoute} from '@react-navigation/native'; import FocusTrap from 'focus-trap-react'; import React, {useMemo} from 'react'; -import BOTTOM_TAB_SCREENS from '@components/FocusTrap/BOTTOM_TAB_SCREENS'; import sharedTrapStack from '@components/FocusTrap/sharedTrapStack'; import TOP_TAB_SCREENS from '@components/FocusTrap/TOP_TAB_SCREENS'; import WIDE_LAYOUT_INACTIVE_SCREENS from '@components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import {isSidebarScreenName} from '@libs/NavigationUtils'; import CONST from '@src/CONST'; import type FocusTrapProps from './FocusTrapProps'; @@ -19,7 +19,7 @@ function FocusTrapForScreen({children, focusTrapSettings}: FocusTrapProps) { return focusTrapSettings.active; } // Focus trap can't be active on bottom tab screens because it would block access to the tab bar. - if (BOTTOM_TAB_SCREENS.find((screen) => screen === route.name)) { + if (isSidebarScreenName(route.name)) { return false; } diff --git a/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts b/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts index 32e063f03109..b98809a14f7c 100644 --- a/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts +++ b/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts @@ -1,4 +1,3 @@ -import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; /** @@ -6,7 +5,6 @@ import SCREENS from '@src/SCREENS'; * focus trap when rendered on a wide screen to allow navigation between them using the keyboard */ const WIDE_LAYOUT_INACTIVE_SCREENS: string[] = [ - NAVIGATORS.BOTTOM_TAB_NAVIGATOR, SCREENS.HOME, SCREENS.SETTINGS.ROOT, SCREENS.REPORT, diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx index 89a9fb21d48f..5b05bae39a37 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx @@ -10,14 +10,12 @@ import Text from '@components/Text'; import useCurrentReportID from '@hooks/useCurrentReportID'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; -import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; -import type {RootStackParamList, State} from '@libs/Navigation/types'; -import Navigation, {navigationRef} from '@navigation/Navigation'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import Navigation from '@navigation/Navigation'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type {Route} from '@src/ROUTES'; -import SCREENS from '@src/SCREENS'; +import ROUTES from '@src/ROUTES'; import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import MentionReportContext from './MentionReportContext'; @@ -74,9 +72,8 @@ function MentionReportRenderer({style, tnode, TDefaultRenderer, ...defaultRender const {reportID, mentionDisplayText} = mentionDetails; let navigationRoute: Route | undefined = reportID ? ROUTES.REPORT_WITH_ID.getRoute(reportID) : undefined; - const topmostCentralPaneRoute = getTopmostCentralPaneRoute(navigationRef.getRootState() as State); const backTo = Navigation.getActiveRoute(); - if (topmostCentralPaneRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) { + if (isSearchTopmostFullScreenRoute()) { navigationRoute = reportID ? ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}) : undefined; } const isCurrentRoomMention = reportID === currentReportIDValue; diff --git a/src/components/PromotedActionsBar.tsx b/src/components/PromotedActionsBar.tsx index e6ce3080ee0a..b1a515097ebb 100644 --- a/src/components/PromotedActionsBar.tsx +++ b/src/components/PromotedActionsBar.tsx @@ -5,15 +5,13 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as HeaderUtils from '@libs/HeaderUtils'; import * as Localize from '@libs/Localize'; -import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; -import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; -import type {RootStackParamList, State} from '@libs/Navigation/types'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import * as ReportActions from '@userActions/Report'; import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import SCREENS from '@src/SCREENS'; import type {ReportAction} from '@src/types/onyx'; import type OnyxReport from '@src/types/onyx/Report'; import Button from './Button'; @@ -93,9 +91,8 @@ const PromotedActions = { Navigation.goBack(); } const targetedReportID = reportID ?? reportAction?.childReportID ?? ''; - const topmostCentralPaneRoute = getTopmostCentralPaneRoute(navigationRef.getRootState() as State); - if (topmostCentralPaneRoute?.name !== SCREENS.SEARCH.CENTRAL_PANE && isTextHold) { + if (isSearchTopmostFullScreenRoute() && isTextHold) { ReportUtils.changeMoneyRequestHoldStatus(reportAction, ROUTES.REPORT_WITH_ID.getRoute(targetedReportID)); return; } diff --git a/src/components/ScrollOffsetContextProvider.tsx b/src/components/ScrollOffsetContextProvider.tsx index 78d8c5ed61fb..f5573fd6b2e4 100644 --- a/src/components/ScrollOffsetContextProvider.tsx +++ b/src/components/ScrollOffsetContextProvider.tsx @@ -4,7 +4,7 @@ import {withOnyx} from 'react-native-onyx'; import usePrevious from '@hooks/usePrevious'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {NavigationPartialRoute, State} from '@libs/Navigation/types'; -import NAVIGATORS from '@src/NAVIGATORS'; +import {isSidebarScreenName} from '@libs/NavigationUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; import type {PriorityMode} from '@src/types/onyx'; @@ -75,14 +75,11 @@ function ScrollOffsetContextProvider({children, priorityMode}: ScrollOffsetConte }, []); const cleanStaleScrollOffsets: ScrollOffsetContextValue['cleanStaleScrollOffsets'] = useCallback((state) => { - const bottomTabNavigator = state.routes.find((route) => route.name === NAVIGATORS.BOTTOM_TAB_NAVIGATOR); - if (bottomTabNavigator?.state && 'routes' in bottomTabNavigator.state) { - const bottomTabNavigatorRoutes = bottomTabNavigator.state.routes; - const scrollOffsetkeysOfExistingScreens = bottomTabNavigatorRoutes.map((route) => getKey(route)); - for (const key of Object.keys(scrollOffsetsRef.current)) { - if (!scrollOffsetkeysOfExistingScreens.includes(key)) { - delete scrollOffsetsRef.current[key]; - } + const sidebarRoutes = state.routes.filter((route) => isSidebarScreenName(route.name)); + const scrollOffsetkeysOfExistingScreens = sidebarRoutes.map((route) => getKey(route)); + for (const key of Object.keys(scrollOffsetsRef.current)) { + if (!scrollOffsetkeysOfExistingScreens.includes(key)) { + delete scrollOffsetsRef.current[key]; } } }, []); diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx index a3ed832a8d06..6ad404d6fddd 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar.tsx @@ -92,7 +92,7 @@ function BottomTabBar({selectedTab}: BottomTabBarProps) { }, [selectedTab]); const navigateToSearch = useCallback(() => { - if (selectedTab === SCREENS.SEARCH.BOTTOM_TAB) { + if (selectedTab === SCREENS.SEARCH.CENTRAL_PANE) { return; } interceptAnonymousUser(() => { diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabNavigationContentWrapper.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabNavigationContentWrapper.tsx deleted file mode 100644 index dd93a6df7b1e..000000000000 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabNavigationContentWrapper.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; -import {View} from 'react-native'; -import ScreenWrapper from '@components/ScreenWrapper'; -import useThemeStyles from '@hooks/useThemeStyles'; -import type {NavigationContentWrapperProps} from '@libs/Navigation/PlatformStackNavigation/types'; - -function BottomTabNavigationContentWrapper({children, displayName}: NavigationContentWrapperProps) { - const styles = useThemeStyles(); - - return ( - - {children} - - ); -} - -export default BottomTabNavigationContentWrapper; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index f816085f5325..4ef2cbb6255f 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -17,29 +17,23 @@ import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import type {HybridAppRoute, Route} from '@src/ROUTES'; import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES'; -import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS'; import type {Screen} from '@src/SCREENS'; +import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import originalCloseRHPFlow from './closeRHPFlow'; import getPolicyIDFromState from './getPolicyIDFromState'; import getStateFromPath from './getStateFromPath'; -import originalGetTopmostReportActionId from './getTopmostReportActionID'; -import originalGetTopmostReportId from './getTopmostReportId'; +import getTopmostReportParam from './getTopmostReportParam'; import isReportOpenInRHP from './isReportOpenInRHP'; import linkingConfig from './linkingConfig'; import createSplitNavigator from './linkingConfig/createSplitNavigator'; +import RELATIONS from './linkingConfig/RELATIONS'; import linkTo from './linkTo'; import getMinimalAction from './linkTo/getMinimalAction'; import navigationRef from './navigationRef'; import setNavigationActionToMicrotaskQueue from './setNavigationActionToMicrotaskQueue'; -import type {NavigationPartialRoute, NavigationStateRoute, RootStackParamList, SplitNavigatorLHNScreen, SplitNavigatorParamListType, State} from './types'; - -const SPLIT_NAVIGATOR_TO_SIDEBAR_MAP: Record = { - [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: SCREENS.HOME, - [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SCREENS.SETTINGS.ROOT, - [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: SCREENS.WORKSPACE.INITIAL, -}; +import type {NavigationPartialRoute, NavigationStateRoute, RootStackParamList, State} from './types'; function getSidebarScreenParams(splitNavigatorRoute: NavigationStateRoute) { if (splitNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { @@ -74,10 +68,10 @@ function canNavigate(methodName: string, params: Record = {}): } // Re-exporting the getTopmostReportId here to fill in default value for state. The getTopmostReportId isn't defined in this file to avoid cyclic dependencies. -const getTopmostReportId = (state = navigationRef.getState()) => originalGetTopmostReportId(state); +const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParam(state, 'reportID'); // Re-exporting the getTopmostReportActionID here to fill in default value for state. The getTopmostReportActionID isn't defined in this file to avoid cyclic dependencies. -const getTopmostReportActionId = (state = navigationRef.getState()) => originalGetTopmostReportActionId(state); +const getTopmostReportActionId = (state = navigationRef.getState()) => getTopmostReportParam(state, 'reportActionID'); // Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies. const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref); @@ -282,7 +276,7 @@ function goBack(fallbackRoute?: Route, shouldPopToTop = false) { const canGoBack = navigationRef.current?.canGoBack(); if (!canGoBack && isSplitNavigatorName(lastRoute?.name) && lastRoute?.state?.routes?.length === 1) { - const name = SPLIT_NAVIGATOR_TO_SIDEBAR_MAP[lastRoute.name]; + const name = RELATIONS.SPLIT_TO_SIDEBAR[lastRoute.name]; const params = getSidebarScreenParams(lastRoute); navigationRef.dispatch({ type: 'REPLACE', diff --git a/src/libs/Navigation/getTopmostCentralPaneRoute.ts b/src/libs/Navigation/getTopmostCentralPaneRoute.ts deleted file mode 100644 index 5ac72281eaf6..000000000000 --- a/src/libs/Navigation/getTopmostCentralPaneRoute.ts +++ /dev/null @@ -1,19 +0,0 @@ -import {isCentralPaneName} from '@libs/NavigationUtils'; -import type {CentralPaneName, NavigationPartialRoute, RootStackParamList, State} from './types'; - -// Get the name of topmost central pane route in the navigation stack. -function getTopmostCentralPaneRoute(state: State): NavigationPartialRoute | undefined { - if (!state) { - return; - } - - const topmostCentralPane = state.routes.filter((route) => isCentralPaneName(route.name)).at(-1); - - if (!topmostCentralPane) { - return; - } - - return topmostCentralPane as NavigationPartialRoute; -} - -export default getTopmostCentralPaneRoute; diff --git a/src/libs/Navigation/getTopmostReportActionID.ts b/src/libs/Navigation/getTopmostReportActionID.ts deleted file mode 100644 index b789d45cc9a6..000000000000 --- a/src/libs/Navigation/getTopmostReportActionID.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type {NavigationState, PartialState} from '@react-navigation/native'; -import NAVIGATORS from '@src/NAVIGATORS'; -import SCREENS from '@src/SCREENS'; -import type {RootStackParamList} from './types'; - -// This function is in a separate file than Navigation.ts to avoid cyclic dependency. - -/** - * Find the last visited report screen in the navigation state and get the linked reportActionID of it. - * - * @param state - The react-navigation state - * @returns - It's possible that there is no report screen - */ -function getTopmostReportActionID(state: NavigationState | NavigationState | PartialState): string | undefined { - if (!state) { - return; - } - - const topmostReportsSplitNavigator = state.routes.filter((route) => route.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR).at(-1); - if (!topmostReportsSplitNavigator?.state) { - return; - } - - const topmostReport = topmostReportsSplitNavigator.state?.routes.filter((route) => route.name === SCREENS.REPORT).at(-1); - - if (!topmostReport || !topmostReport?.params) { - return; - } - - const reportActionID = 'reportActionID' in topmostReport.params && topmostReport.params.reportActionID; - - if (typeof reportActionID !== 'string') { - return; - } - - return reportActionID; -} - -export default getTopmostReportActionID; diff --git a/src/libs/Navigation/getTopmostReportId.ts b/src/libs/Navigation/getTopmostReportParam.ts similarity index 68% rename from src/libs/Navigation/getTopmostReportId.ts rename to src/libs/Navigation/getTopmostReportParam.ts index 0969f46b6b5d..30354c7c6dd0 100644 --- a/src/libs/Navigation/getTopmostReportId.ts +++ b/src/libs/Navigation/getTopmostReportParam.ts @@ -11,7 +11,11 @@ import type {RootStackParamList} from './types'; * @param state - The react-navigation state * @returns - It's possible that there is no report screen */ -function getTopmostReportId(state: NavigationState | NavigationState | PartialState): string | undefined { + +type State = NavigationState | NavigationState | PartialState; +type ReportParam = 'reportID' | 'reportActionID'; + +function getTopmostReportParam(state: State, reportParam: ReportParam): string | undefined { if (!state) { return; } @@ -28,12 +32,9 @@ function getTopmostReportId(state: NavigationState | NavigationState; - return topmostReportId; + return topmostReportParams?.[reportParam]; } -export default getTopmostReportId; +export default getTopmostReportParam; diff --git a/src/libs/Navigation/getTopmostWorkspaceRoute.ts b/src/libs/Navigation/getTopmostWorkspaceRoute.ts deleted file mode 100644 index 04e1237643dd..000000000000 --- a/src/libs/Navigation/getTopmostWorkspaceRoute.ts +++ /dev/null @@ -1,28 +0,0 @@ -import NAVIGATORS from '@src/NAVIGATORS'; -import type {NavigationPartialRoute, RootStackParamList, State, WorkspaceScreenName} from './types'; - -// Get the name of topmost workspace navigator route in the navigation stack. -function getTopmostWorkspaceRoute(state: State): NavigationPartialRoute | undefined { - if (!state) { - return; - } - - const topmostWorkspaceRoute = state.routes.filter((route) => route.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR).at(-1); - - if (!topmostWorkspaceRoute) { - return; - } - - if (topmostWorkspaceRoute.state) { - // There will be at least one route in the workspace navigator. - const {name, params} = topmostWorkspaceRoute.state.routes.at(-1) as NavigationPartialRoute; - - return {name, params}; - } - - if (!!topmostWorkspaceRoute.params && 'screen' in topmostWorkspaceRoute.params) { - return {name: topmostWorkspaceRoute.params.screen as WorkspaceScreenName, params: topmostWorkspaceRoute.params.params}; - } -} - -export default getTopmostWorkspaceRoute; diff --git a/src/libs/Navigation/isSearchTopmostFullScreenRoute.ts b/src/libs/Navigation/isSearchTopmostFullScreenRoute.ts index eaae1f807489..5599ec650c14 100644 --- a/src/libs/Navigation/isSearchTopmostFullScreenRoute.ts +++ b/src/libs/Navigation/isSearchTopmostFullScreenRoute.ts @@ -10,7 +10,7 @@ const isSearchTopmostFullScreenRoute = (): boolean => { return false; } - return rootState.routes.filter((route) => isFullScreenName(route.name)).at(-1)?.name === SCREENS.SEARCH.CENTRAL_PANE; + return rootState.routes.findLast((route) => isFullScreenName(route.name))?.name === SCREENS.SEARCH.CENTRAL_PANE; }; export default isSearchTopmostFullScreenRoute; diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/index.ts b/src/libs/Navigation/linkingConfig/RELATIONS/index.ts index 90865784f68c..3c4c9140d2d8 100644 --- a/src/libs/Navigation/linkingConfig/RELATIONS/index.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/index.ts @@ -25,4 +25,5 @@ export default { SIDEBAR_TO_RHP, WORKSPACE_TO_RHP, SIDEBAR_TO_SPLIT, + SPLIT_TO_SIDEBAR: createInverseRelation(SIDEBAR_TO_RHP), }; diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 677765b0879e..b8546716d96f 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -9,8 +9,6 @@ import createNormalizedConfigs from './createNormalizedConfigs'; // Moved to a separate file to avoid cyclic dependencies. const config: LinkingOptions['config'] = { - // initialRouteName: NAVIGATORS.BOTTOM_TAB_NAVIGATOR, - // initialRouteName: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, screens: { // Main Routes [SCREENS.VALIDATE_LOGIN]: ROUTES.VALIDATE_LOGIN, diff --git a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts index 9ffdcae2224b..8954e48955f8 100644 --- a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts +++ b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts @@ -1,12 +1,9 @@ import {getPathFromState} from '@react-navigation/native'; -import type {RootStackParamList, State} from '@libs/Navigation/types'; -import {isFullScreenName, removePolicyIDParamFromState} from '@libs/NavigationUtils'; +import {isFullScreenName} from '@libs/NavigationUtils'; import NAVIGATORS from '@src/NAVIGATORS'; const customGetPathFromState: typeof getPathFromState = (state, options) => { - // For the Home page we should remove policyID from the params, because on small screens it's displayed twice in the URL - const stateWithoutPolicyID = removePolicyIDParamFromState(state as State); - const path = getPathFromState(stateWithoutPolicyID, options); + const path = getPathFromState(state, options); const fullScreenRoute = state.routes.findLast((route) => isFullScreenName(route.name)); const shouldAddPolicyID = fullScreenRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR; diff --git a/src/libs/Navigation/shouldSetScreenBlurred/index.tsx b/src/libs/Navigation/shouldSetScreenBlurred/index.tsx deleted file mode 100644 index 2461187046d8..000000000000 --- a/src/libs/Navigation/shouldSetScreenBlurred/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @param navigationIndex - * - * Decides whether to set screen to blurred state. - * - * Allow freezing the first screen and more in the stack only on - * web and desktop platforms. The reason is that in the case of - * LHN, we have FlashList rendering in the back while we are on - * Settings screen. - */ -const shouldSetScreenBlurred = (navigationIndex: number) => navigationIndex > 1; - -export default shouldSetScreenBlurred; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 569fba200f44..304aa93c13f0 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1569,12 +1569,6 @@ type ExplanationModalNavigatorParamList = { [SCREENS.EXPLANATION_MODAL.ROOT]: undefined; }; -type BottomTabNavigatorParamList = { - [SCREENS.HOME]: {policyID?: string}; - [SCREENS.SEARCH.BOTTOM_TAB]: undefined; - [SCREENS.SETTINGS.ROOT]: {policyID?: string}; -}; - type SharedScreensParamList = { [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: NavigatorScreenParams; [SCREENS.TRANSITION_BETWEEN_APPS]: { @@ -1729,8 +1723,6 @@ type DebugParamList = { type RootStackParamList = PublicScreensParamList & AuthScreensParamList & LeftModalNavigatorParamList; -type BottomTabName = keyof BottomTabNavigatorParamList; - type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; type CentralPaneName = keyof CentralPaneScreensParamList; @@ -1764,8 +1756,6 @@ export type { CentralPaneName, BackToParams, BackToAndForwardToParms, - BottomTabName, - BottomTabNavigatorParamList, DetailsNavigatorParamList, EditRequestNavigatorParamList, EnablePaymentsNavigatorParamList, diff --git a/src/libs/NavigationUtils.ts b/src/libs/NavigationUtils.ts index 65c0022d2bc2..139694afcfe6 100644 --- a/src/libs/NavigationUtils.ts +++ b/src/libs/NavigationUtils.ts @@ -1,74 +1,45 @@ -import cloneDeep from 'lodash/cloneDeep'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; -import type {CentralPaneName, FullScreenName, OnboardingFlowName, RootStackParamList, SplitNavigatorName, State} from './Navigation/types'; +import type {FullScreenName, OnboardingFlowName, SplitNavigatorLHNScreen, SplitNavigatorName} from './Navigation/types'; const SPLIT_NAVIGATORS = [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]; - -const SPLIT_NAVIGATORS_SET = new Set(SPLIT_NAVIGATORS); - -const FULL_SCREEN_ROUTES_SET = new Set([...SPLIT_NAVIGATORS, SCREENS.SEARCH.CENTRAL_PANE]); - -const CENTRAL_PANE_SCREEN_NAMES = new Set([ - SCREENS.SETTINGS.WORKSPACES, - SCREENS.SETTINGS.PREFERENCES.ROOT, - SCREENS.SETTINGS.SECURITY, - SCREENS.SETTINGS.PROFILE.ROOT, - SCREENS.SETTINGS.WALLET.ROOT, - SCREENS.SETTINGS.ABOUT, - SCREENS.SETTINGS.TROUBLESHOOT, - SCREENS.SETTINGS.SAVE_THE_WORLD, - SCREENS.SETTINGS.SUBSCRIPTION.ROOT, - SCREENS.SEARCH.CENTRAL_PANE, - SCREENS.REPORT, -]); - -const ONBOARDING_SCREEN_NAMES = new Set([ +const FULL_SCREENS = [...SPLIT_NAVIGATORS, SCREENS.SEARCH.CENTRAL_PANE]; +const SIDEBARS = [SCREENS.HOME, SCREENS.SETTINGS.ROOT, SCREENS.WORKSPACE.INITIAL]; +const ONBOARDING_SCREENS = [ SCREENS.ONBOARDING.PERSONAL_DETAILS, SCREENS.ONBOARDING.PURPOSE, SCREENS.ONBOARDING_MODAL.ONBOARDING, SCREENS.ONBOARDING.EMPLOYEES, SCREENS.ONBOARDING.ACCOUNTING, -]); +]; -const removePolicyIDParamFromState = (state: State) => { - const stateCopy = cloneDeep(state); - // const bottomTabRoute = getTopmostBottomTabRoute(stateCopy); - // if (bottomTabRoute?.params && 'policyID' in bottomTabRoute.params) { - // delete bottomTabRoute.params.policyID; - // } - return stateCopy; -}; - -function isCentralPaneName(screen: string | undefined): screen is CentralPaneName { - if (!screen) { - return false; - } - return CENTRAL_PANE_SCREEN_NAMES.has(screen as CentralPaneName); -} +const SPLIT_NAVIGATORS_SET = new Set(SPLIT_NAVIGATORS); +const FULL_SCREENS_SET = new Set(FULL_SCREENS); +const SIDEBARS_SET = new Set(SIDEBARS); +const ONBOARDING_SCREENS_SET = new Set(ONBOARDING_SCREENS); -function isOnboardingFlowName(screen: string | undefined): screen is OnboardingFlowName { +function checkIsScreenHasMatchingNameToSetValues(screen: string | undefined, set: Set): screen is T { if (!screen) { return false; } - return ONBOARDING_SCREEN_NAMES.has(screen as OnboardingFlowName); + return set.has(screen as T); } -function isSplitNavigatorName(screen: string | undefined): screen is SplitNavigatorName { - if (!screen) { - return false; - } +function isOnboardingFlowName(screen: string | undefined) { + return checkIsScreenHasMatchingNameToSetValues(screen, ONBOARDING_SCREENS_SET); +} - return SPLIT_NAVIGATORS_SET.has(screen as SplitNavigatorName); +function isSplitNavigatorName(screen: string | undefined) { + return checkIsScreenHasMatchingNameToSetValues(screen, SPLIT_NAVIGATORS_SET); } -function isFullScreenName(screen: string | undefined): screen is FullScreenName { - if (!screen) { - return false; - } +function isFullScreenName(screen: string | undefined) { + return checkIsScreenHasMatchingNameToSetValues(screen, FULL_SCREENS_SET); +} - return FULL_SCREEN_ROUTES_SET.has(screen as FullScreenName); +function isSidebarScreenName(screen: string | undefined) { + return checkIsScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); } -export {isCentralPaneName, isFullScreenName, isOnboardingFlowName, isSplitNavigatorName, removePolicyIDParamFromState}; +export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName}; diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index f0e8d2ba1781..bfc3fad7a71f 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -1,4 +1,4 @@ -import {useIsFocused as useIsFocusedOriginal, useNavigationState} from '@react-navigation/native'; +import {useIsFocused} from '@react-navigation/native'; import type {ImageContentFit} from 'expo-image'; import type {ForwardedRef} from 'react'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; @@ -23,9 +23,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import getIconForAction from '@libs/getIconForAction'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; -import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; import Navigation from '@libs/Navigation/Navigation'; -import type {CentralPaneName, NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; import {hasSeenTourSelector} from '@libs/onboardingSelectors'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -43,21 +41,11 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type {QuickActionName} from '@src/types/onyx/QuickAction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; -// On small screen we hide the search page from central pane to show the search bottom tab page with bottom tab bar. -// We need to take this in consideration when checking if the screen is focused. -const useIsFocused = () => { - const {shouldUseNarrowLayout} = useResponsiveLayout(); - const isFocused = useIsFocusedOriginal(); - const topmostCentralPane = useNavigationState | undefined>(getTopmostCentralPaneRoute); - return isFocused || (topmostCentralPane?.name === SCREENS.SEARCH.CENTRAL_PANE && shouldUseNarrowLayout); -}; - type PolicySelector = Pick; type FloatingActionButtonAndPopoverProps = { From 4ace213f360295f972480a7d316c4f88af1d8b36 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 25 Nov 2024 11:01:02 +0100 Subject: [PATCH 02/26] Cleanup config.ts --- src/libs/Navigation/linkingConfig/config.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index b8546716d96f..3be3be9d15ec 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -60,18 +60,6 @@ const config: LinkingOptions['config'] = { // [SCREENS.SETTINGS.SAVE_THE_WORLD]: ROUTES.SETTINGS_SAVE_THE_WORLD, // [SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: ROUTES.SETTINGS_SUBSCRIPTION, - // Sidebar - // [NAVIGATORS.BOTTOM_TAB_NAVIGATOR]: { - // path: ROUTES.ROOT, - // initialRouteName: SCREENS.HOME, - // screens: { - // [SCREENS.HOME]: ROUTES.HOME, - // // [SCREENS.SETTINGS.ROOT]: { - // // path: ROUTES.SETTINGS, - // // }, - // }, - // }, - [SCREENS.NOT_FOUND]: '*', [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: { screens: { From fd99fa881d035834e52698e6bd49ec6895df8cc1 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 25 Nov 2024 13:08:39 +0100 Subject: [PATCH 03/26] Remove subscribe --- src/libs/Navigation/linkingConfig/index.ts | 2 - .../linkingConfig/subscribe/index.native.ts | 40 ------------------- .../linkingConfig/subscribe/index.ts | 7 ---- 3 files changed, 49 deletions(-) delete mode 100644 src/libs/Navigation/linkingConfig/subscribe/index.native.ts delete mode 100644 src/libs/Navigation/linkingConfig/subscribe/index.ts diff --git a/src/libs/Navigation/linkingConfig/index.ts b/src/libs/Navigation/linkingConfig/index.ts index 1f556aa67809..3e958d593ec9 100644 --- a/src/libs/Navigation/linkingConfig/index.ts +++ b/src/libs/Navigation/linkingConfig/index.ts @@ -5,7 +5,6 @@ import config from './config'; import customGetPathFromState from './customGetPathFromState'; import getAdaptedStateFromPath from './getAdaptedStateFromPath'; import prefixes from './prefixes'; -import subscribe from './subscribe'; const linkingConfig: LinkingOptions = { getStateFromPath: (...args) => { @@ -14,7 +13,6 @@ const linkingConfig: LinkingOptions = { // ResultState | undefined is the type this function expect. return adaptedState; }, - subscribe, getPathFromState: customGetPathFromState, prefixes, config, diff --git a/src/libs/Navigation/linkingConfig/subscribe/index.native.ts b/src/libs/Navigation/linkingConfig/subscribe/index.native.ts deleted file mode 100644 index 46720e9884e9..000000000000 --- a/src/libs/Navigation/linkingConfig/subscribe/index.native.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import type {LinkingOptions} from '@react-navigation/native'; -import {findFocusedRoute, getStateFromPath} from '@react-navigation/native'; -import extractPathFromURL from '@react-navigation/native/src/extractPathFromURL'; -import {Linking} from 'react-native'; -import Navigation from '@libs/Navigation/Navigation'; -import config from '@navigation/linkingConfig/config'; -import prefixes from '@navigation/linkingConfig/prefixes'; -import type {RootStackParamList} from '@navigation/types'; -import type {Route} from '@src/ROUTES'; -import SCREENS from '@src/SCREENS'; - -// This field in linkingConfig is supported on native only. -const subscribe: LinkingOptions['subscribe'] = (listener) => { - // We need to override the default behaviour for the deep link to search screen. - // Even on mobile narrow layout, this screen need to push two screens on the stack to work (bottom tab and central pane). - // That's why we are going to handle it with our navigate function instead the default react-navigation one. - const linkingSubscription = Linking.addEventListener('url', ({url}) => { - const path = extractPathFromURL(prefixes, url); - - if (path) { - const stateFromPath = getStateFromPath(path, config); - if (stateFromPath) { - const focusedRoute = findFocusedRoute(stateFromPath); - if (focusedRoute && focusedRoute.name === SCREENS.SEARCH.CENTRAL_PANE) { - Navigation.navigate(path as Route); - return; - } - } - } - - listener(url); - }); - return () => { - // Clean up the event listeners - linkingSubscription.remove(); - }; -}; - -export default subscribe; diff --git a/src/libs/Navigation/linkingConfig/subscribe/index.ts b/src/libs/Navigation/linkingConfig/subscribe/index.ts deleted file mode 100644 index 74ef4133cb55..000000000000 --- a/src/libs/Navigation/linkingConfig/subscribe/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type {LinkingOptions} from '@react-navigation/native'; -import type {RootStackParamList} from '@libs/Navigation/types'; - -// This field in linkingConfig is supported on native only. -const subscribe: LinkingOptions['subscribe'] = undefined; - -export default subscribe; From d54df17da16b1527fc37a1850050a95b681cfaf6 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 25 Nov 2024 14:21:27 +0100 Subject: [PATCH 04/26] Remove Navigation.removeScreenFromNavigationState --- src/libs/Navigation/Navigation.ts | 16 ---------------- src/pages/workspace/AccessOrNotFoundWrapper.tsx | 9 --------- 2 files changed, 25 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 4ef2cbb6255f..8013eb6c20c3 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -17,7 +17,6 @@ import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import type {HybridAppRoute, Route} from '@src/ROUTES'; import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES'; -import type {Screen} from '@src/SCREENS'; import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -461,20 +460,6 @@ const dismissModalWithReport = (report: OnyxEntry) => { isNavigationReady().then(() => navigateToReportWithPolicyCheck({report})); }; -function removeScreenFromNavigationState(screen: Screen) { - isNavigationReady().then(() => { - navigationRef.dispatch((state) => { - const routes = state.routes?.filter((item) => item.name !== screen); - - return CommonActions.reset({ - ...state, - routes, - index: routes.length < state.routes.length ? state.index - 1 : state.index, - }); - }); - }); -} - export default { setShouldPopAllStateOnUP, navigate, @@ -499,7 +484,6 @@ export default { setNavigationActionToMicrotaskQueue, navigateToReportWithPolicyCheck, goUp, - removeScreenFromNavigationState, }; export {navigationRef}; diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index 7a260d876371..83a24e2084d3 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -17,7 +17,6 @@ import type {IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type {PolicyFeatureName} from '@src/types/onyx/Policy'; import callOrReturn from '@src/types/utils/callOrReturn'; @@ -166,14 +165,6 @@ function AccessOrNotFoundWrapper({ setIsPolicyFeatureEnabled(isFeatureEnabled); }, [pendingField, isOffline, isFeatureEnabled]); - useEffect(() => { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (isLoadingReportData || !isPolicyNotAccessible) { - return; - } - Navigation.removeScreenFromNavigationState(SCREENS.WORKSPACE.INITIAL); - }, [isLoadingReportData, isPolicyNotAccessible]); - if (shouldShowFullScreenLoadingIndicator) { return ; } From 9280e9e511018832dcbb22218cb2bb38263bad1b Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 25 Nov 2024 14:38:15 +0100 Subject: [PATCH 05/26] Fix typo in NavigationUtils.ts --- src/libs/NavigationUtils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/NavigationUtils.ts b/src/libs/NavigationUtils.ts index 139694afcfe6..6ec44e62d690 100644 --- a/src/libs/NavigationUtils.ts +++ b/src/libs/NavigationUtils.ts @@ -18,7 +18,7 @@ const FULL_SCREENS_SET = new Set(FULL_SCREENS); const SIDEBARS_SET = new Set(SIDEBARS); const ONBOARDING_SCREENS_SET = new Set(ONBOARDING_SCREENS); -function checkIsScreenHasMatchingNameToSetValues(screen: string | undefined, set: Set): screen is T { +function checkIfScreenHasMatchingNameToSetValues(screen: string | undefined, set: Set): screen is T { if (!screen) { return false; } @@ -27,19 +27,19 @@ function checkIsScreenHasMatchingNameToSetValues(screen: strin } function isOnboardingFlowName(screen: string | undefined) { - return checkIsScreenHasMatchingNameToSetValues(screen, ONBOARDING_SCREENS_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, ONBOARDING_SCREENS_SET); } function isSplitNavigatorName(screen: string | undefined) { - return checkIsScreenHasMatchingNameToSetValues(screen, SPLIT_NAVIGATORS_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, SPLIT_NAVIGATORS_SET); } function isFullScreenName(screen: string | undefined) { - return checkIsScreenHasMatchingNameToSetValues(screen, FULL_SCREENS_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, FULL_SCREENS_SET); } function isSidebarScreenName(screen: string | undefined) { - return checkIsScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); } export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName}; From 9fbccec67a3c6d0697935a2c6b842e65fa3fd082 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 25 Nov 2024 20:24:16 +0100 Subject: [PATCH 06/26] Add navigation helpers --- .../DeeplinkWrapper/index.website.tsx | 2 +- .../MentionReportRenderer/index.tsx | 2 +- src/components/Lottie/index.tsx | 2 +- src/components/PromotedActionsBar.tsx | 2 +- src/components/Search/index.tsx | 2 +- .../Navigation/AppNavigator/AuthScreens.tsx | 2 +- .../Navigators/ReportsSplitNavigator.tsx | 2 +- .../CustomRouter.ts | 2 +- .../GetStateForActionHandlers.ts | 5 ++--- .../SplitStackRouter.ts | 2 +- src/libs/Navigation/Navigation.ts | 16 +++++++------- src/libs/Navigation/NavigationRoot.tsx | 3 +-- .../Navigation/{ => helpers}/closeRHPFlow.ts | 2 +- .../createNormalizedConfigs.ts | 0 .../createSplitNavigator.ts | 3 ++- .../customGetPathFromState.ts | 0 .../{ => helpers}/extractPolicyIDFromQuery.ts | 2 +- .../extrapolateStateFromParams.ts | 0 .../getAdaptedStateFromPath.ts | 6 +++--- .../getOnboardingAdaptedState.ts | 0 .../getParamsFromRoute.ts | 2 +- .../{ => helpers}/getPolicyIDFromState.ts | 2 +- .../{ => helpers}/getStateFromPath.ts | 2 +- .../{ => helpers}/getTopmostReportParam.ts | 2 +- .../{ => helpers}/getTopmostRouteName.ts | 0 src/libs/Navigation/helpers/index.ts | 21 +++++++++++++++++++ .../{ => helpers}/isReportOpenInRHP.ts | 0 .../isSearchTopmostFullScreenRoute.ts | 4 ++-- .../{ => helpers}/isSideModalNavigator.ts | 0 .../normalizePath.ts | 0 .../replacePathInNestedState.ts | 0 .../setNavigationActionToMicrotaskQueue.ts | 0 .../{ => helpers}/shouldOpenOnAdminRoom.ts | 2 +- .../shouldPreventDeeplinkPrompt.ts | 0 src/libs/Navigation/linkTo/index.ts | 5 ++--- src/libs/Navigation/linkingConfig/config.ts | 4 ++-- src/libs/Navigation/linkingConfig/index.ts | 4 ++-- src/libs/ReportActionComposeFocusManager.ts | 4 ++-- src/libs/actions/IOU.ts | 2 +- src/libs/actions/Welcome/OnboardingFlow.ts | 2 +- src/libs/navigateAfterOnboarding.ts | 2 +- src/pages/EditReportFieldPage.tsx | 2 +- src/pages/home/report/ReportActionsList.tsx | 2 +- src/pages/settings/InitialSettingsPage.tsx | 2 +- src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- 45 files changed, 71 insertions(+), 50 deletions(-) rename src/libs/Navigation/{ => helpers}/closeRHPFlow.ts (94%) rename src/libs/Navigation/{linkingConfig => helpers}/createNormalizedConfigs.ts (100%) rename src/libs/Navigation/{linkingConfig => helpers}/createSplitNavigator.ts (91%) rename src/libs/Navigation/{linkingConfig => helpers}/customGetPathFromState.ts (100%) rename src/libs/Navigation/{ => helpers}/extractPolicyIDFromQuery.ts (89%) rename src/libs/Navigation/{ => helpers}/extrapolateStateFromParams.ts (100%) rename src/libs/Navigation/{linkingConfig => helpers}/getAdaptedStateFromPath.ts (98%) rename src/libs/Navigation/{linkingConfig => helpers}/getOnboardingAdaptedState.ts (100%) rename src/libs/Navigation/{linkingConfig => helpers}/getParamsFromRoute.ts (80%) rename src/libs/Navigation/{ => helpers}/getPolicyIDFromState.ts (97%) rename src/libs/Navigation/{ => helpers}/getStateFromPath.ts (93%) rename src/libs/Navigation/{ => helpers}/getTopmostReportParam.ts (95%) rename src/libs/Navigation/{ => helpers}/getTopmostRouteName.ts (100%) create mode 100644 src/libs/Navigation/helpers/index.ts rename src/libs/Navigation/{ => helpers}/isReportOpenInRHP.ts (100%) rename src/libs/Navigation/{ => helpers}/isSearchTopmostFullScreenRoute.ts (77%) rename src/libs/Navigation/{ => helpers}/isSideModalNavigator.ts (100%) rename src/libs/Navigation/{linkingConfig => helpers}/normalizePath.ts (100%) rename src/libs/Navigation/{linkingConfig => helpers}/replacePathInNestedState.ts (100%) rename src/libs/Navigation/{ => helpers}/setNavigationActionToMicrotaskQueue.ts (100%) rename src/libs/Navigation/{ => helpers}/shouldOpenOnAdminRoom.ts (75%) rename src/libs/Navigation/{ => helpers}/shouldPreventDeeplinkPrompt.ts (100%) diff --git a/src/components/DeeplinkWrapper/index.website.tsx b/src/components/DeeplinkWrapper/index.website.tsx index 73427f0d11aa..9848902a817f 100644 --- a/src/components/DeeplinkWrapper/index.website.tsx +++ b/src/components/DeeplinkWrapper/index.website.tsx @@ -1,9 +1,9 @@ import {Str} from 'expensify-common'; import {useEffect, useRef, useState} from 'react'; import * as Browser from '@libs/Browser'; +import {shouldPreventDeeplinkPrompt} from '@libs/Navigation/helpers'; import Navigation from '@libs/Navigation/Navigation'; import navigationRef from '@libs/Navigation/navigationRef'; -import shouldPreventDeeplinkPrompt from '@libs/Navigation/shouldPreventDeeplinkPrompt'; import * as App from '@userActions/App'; import * as Link from '@userActions/Link'; import * as Session from '@userActions/Session'; diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx index 5b05bae39a37..7dd36d372d96 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/index.tsx @@ -10,7 +10,7 @@ import Text from '@components/Text'; import useCurrentReportID from '@hooks/useCurrentReportID'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@navigation/Navigation'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; diff --git a/src/components/Lottie/index.tsx b/src/components/Lottie/index.tsx index 017d68aa4b56..190b24cbbf7b 100644 --- a/src/components/Lottie/index.tsx +++ b/src/components/Lottie/index.tsx @@ -9,7 +9,7 @@ import useAppState from '@hooks/useAppState'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Browser from '@libs/Browser'; -import isSideModalNavigator from '@libs/Navigation/isSideModalNavigator'; +import isSideModalNavigator from '@libs/Navigation/helpers/isSideModalNavigator'; import CONST from '@src/CONST'; import {useSplashScreenStateContext} from '@src/SplashScreenStateContext'; diff --git a/src/components/PromotedActionsBar.tsx b/src/components/PromotedActionsBar.tsx index b1a515097ebb..be4c734608c7 100644 --- a/src/components/PromotedActionsBar.tsx +++ b/src/components/PromotedActionsBar.tsx @@ -5,7 +5,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as HeaderUtils from '@libs/HeaderUtils'; import * as Localize from '@libs/Localize'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import * as ReportActions from '@userActions/Report'; diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 9664c76c81ea..7675866017d4 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -19,7 +19,7 @@ import * as SearchActions from '@libs/actions/Search'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import Log from '@libs/Log'; import memoize from '@libs/memoize'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index a98a5274e012..f73f424ccacb 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -1,5 +1,5 @@ -import {findFocusedRoute} from '@react-navigation/native'; import type {RouteProp} from '@react-navigation/native'; +import {findFocusedRoute} from '@react-navigation/native'; import React, {memo, useEffect, useRef, useState} from 'react'; import {NativeModules, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; diff --git a/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx index f5e90411722d..73972199e7b7 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx @@ -7,7 +7,7 @@ import createSplitStackNavigator from '@libs/Navigation/AppNavigator/createSplit import FreezeWrapper from '@libs/Navigation/AppNavigator/FreezeWrapper'; import useRootNavigatorOptions from '@libs/Navigation/AppNavigator/useRootNavigatorOptions'; import getCurrentUrl from '@libs/Navigation/currentUrl'; -import shouldOpenOnAdminRoom from '@libs/Navigation/shouldOpenOnAdminRoom'; +import shouldOpenOnAdminRoom from '@libs/Navigation/helpers/shouldOpenOnAdminRoom'; import type {ReportsSplitNavigatorParamList} from '@libs/Navigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; diff --git a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts index f678425e2ec5..ae3815e91997 100644 --- a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts @@ -3,7 +3,7 @@ import {findFocusedRoute, StackRouter} from '@react-navigation/native'; import type {ParamListBase} from '@react-navigation/routers'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; import * as Localize from '@libs/Localize'; -import isSideModalNavigator from '@libs/Navigation/isSideModalNavigator'; +import {isSideModalNavigator} from '@libs/Navigation/helpers'; import {isOnboardingFlowName} from '@libs/NavigationUtils'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; diff --git a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/GetStateForActionHandlers.ts index b2af8cd41f98..1a952c0c6caa 100644 --- a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/GetStateForActionHandlers.ts +++ b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/GetStateForActionHandlers.ts @@ -2,12 +2,12 @@ import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigatio import {StackActions} from '@react-navigation/native'; import type {ParamListBase, Router} from '@react-navigation/routers'; import Log from '@libs/Log'; -import getPolicyIDFromState from '@libs/Navigation/getPolicyIDFromState'; +import getPolicyIDFromState from '@libs/Navigation/helpers/getPolicyIDFromState'; import type {RootStackParamList, State} from '@libs/Navigation/types'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; -import type {DismissModalActionType, PushActionType, SwitchPolicyIdActionType} from './types'; +import type {PushActionType, SwitchPolicyIdActionType} from './types'; const MODAL_ROUTES_TO_DISMISS: string[] = [ NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, @@ -137,7 +137,6 @@ function handlePushSearchPageAction( function handleDismissModalAction( state: StackNavigationState, - action: DismissModalActionType, configOptions: RouterConfigOptions, stackRouter: Router, CommonActions.Action | StackActionType>, ) { diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts index 6dd910985b41..3bc1e50717ec 100644 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts +++ b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts @@ -2,7 +2,7 @@ import type {CommonActions, ParamListBase, PartialState, RouterConfigOptions, St import {StackActions, StackRouter} from '@react-navigation/native'; import pick from 'lodash/pick'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; -import getParamsFromRoute from '@libs/Navigation/linkingConfig/getParamsFromRoute'; +import {getParamsFromRoute} from '@libs/Navigation/helpers'; import navigationRef from '@libs/Navigation/navigationRef'; import SCREENS from '@src/SCREENS'; import type {SplitStackNavigatorRouterOptions} from './types'; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 8013eb6c20c3..b1d32c5f6016 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -20,18 +20,20 @@ import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES'; import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import originalCloseRHPFlow from './closeRHPFlow'; -import getPolicyIDFromState from './getPolicyIDFromState'; -import getStateFromPath from './getStateFromPath'; -import getTopmostReportParam from './getTopmostReportParam'; -import isReportOpenInRHP from './isReportOpenInRHP'; +import { + createSplitNavigator, + getPolicyIDFromState, + getStateFromPath, + getTopmostReportParam, + isReportOpenInRHP, + closeRHPFlow as originalCloseRHPFlow, + setNavigationActionToMicrotaskQueue, +} from './helpers'; import linkingConfig from './linkingConfig'; -import createSplitNavigator from './linkingConfig/createSplitNavigator'; import RELATIONS from './linkingConfig/RELATIONS'; import linkTo from './linkTo'; import getMinimalAction from './linkTo/getMinimalAction'; import navigationRef from './navigationRef'; -import setNavigationActionToMicrotaskQueue from './setNavigationActionToMicrotaskQueue'; import type {NavigationPartialRoute, NavigationStateRoute, RootStackParamList, State} from './types'; function getSidebarScreenParams(splitNavigatorRoute: NavigationStateRoute) { diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 03d761575400..99723d3422a9 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -23,9 +23,8 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import AppNavigator from './AppNavigator'; import {cleanPreservedSplitNavigatorStates} from './AppNavigator/createSplitStackNavigator/usePreserveSplitNavigatorState'; +import {customGetPathFromState, getAdaptedStateFromPath} from './helpers'; import linkingConfig from './linkingConfig'; -import customGetPathFromState from './linkingConfig/customGetPathFromState'; -import getAdaptedStateFromPath from './linkingConfig/getAdaptedStateFromPath'; import Navigation, {navigationRef} from './Navigation'; import setupCustomAndroidBackHandler from './setupCustomAndroidBackHandler'; diff --git a/src/libs/Navigation/closeRHPFlow.ts b/src/libs/Navigation/helpers/closeRHPFlow.ts similarity index 94% rename from src/libs/Navigation/closeRHPFlow.ts rename to src/libs/Navigation/helpers/closeRHPFlow.ts index 9bc40f51f472..0f814ca13bb7 100644 --- a/src/libs/Navigation/closeRHPFlow.ts +++ b/src/libs/Navigation/helpers/closeRHPFlow.ts @@ -1,8 +1,8 @@ import type {NavigationContainerRef} from '@react-navigation/native'; import {StackActions} from '@react-navigation/native'; import Log from '@libs/Log'; +import type {RootStackParamList} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; -import type {RootStackParamList} from './types'; /** * Closes the last RHP flow, if there is only one, closes the entire RHP. diff --git a/src/libs/Navigation/linkingConfig/createNormalizedConfigs.ts b/src/libs/Navigation/helpers/createNormalizedConfigs.ts similarity index 100% rename from src/libs/Navigation/linkingConfig/createNormalizedConfigs.ts rename to src/libs/Navigation/helpers/createNormalizedConfigs.ts diff --git a/src/libs/Navigation/linkingConfig/createSplitNavigator.ts b/src/libs/Navigation/helpers/createSplitNavigator.ts similarity index 91% rename from src/libs/Navigation/linkingConfig/createSplitNavigator.ts rename to src/libs/Navigation/helpers/createSplitNavigator.ts index c2d09d28dc87..a43e5a83d7ab 100644 --- a/src/libs/Navigation/linkingConfig/createSplitNavigator.ts +++ b/src/libs/Navigation/helpers/createSplitNavigator.ts @@ -1,6 +1,6 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; +import LHN_TO_SPLIT_NAVIGATOR_NAME from '@libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING'; import type {NavigationPartialRoute, SplitNavigatorByLHN, SplitNavigatorLHNScreen, SplitNavigatorParamListType} from '@libs/Navigation/types'; -import LHN_TO_SPLIT_NAVIGATOR_NAME from './RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING'; type ExtractRouteType = Extract; @@ -25,4 +25,5 @@ function createSplitNavigator( params: splitNavigatorParams, }; } + export default createSplitNavigator; diff --git a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts b/src/libs/Navigation/helpers/customGetPathFromState.ts similarity index 100% rename from src/libs/Navigation/linkingConfig/customGetPathFromState.ts rename to src/libs/Navigation/helpers/customGetPathFromState.ts diff --git a/src/libs/Navigation/extractPolicyIDFromQuery.ts b/src/libs/Navigation/helpers/extractPolicyIDFromQuery.ts similarity index 89% rename from src/libs/Navigation/extractPolicyIDFromQuery.ts rename to src/libs/Navigation/helpers/extractPolicyIDFromQuery.ts index f091690c16f2..d37ded16b4b5 100644 --- a/src/libs/Navigation/extractPolicyIDFromQuery.ts +++ b/src/libs/Navigation/helpers/extractPolicyIDFromQuery.ts @@ -1,5 +1,5 @@ +import type {NavigationPartialRoute} from '@libs/Navigation/types'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; -import type {NavigationPartialRoute} from './types'; function extractPolicyIDFromQuery(route?: NavigationPartialRoute) { if (!route?.params) { diff --git a/src/libs/Navigation/extrapolateStateFromParams.ts b/src/libs/Navigation/helpers/extrapolateStateFromParams.ts similarity index 100% rename from src/libs/Navigation/extrapolateStateFromParams.ts rename to src/libs/Navigation/helpers/extrapolateStateFromParams.ts diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts similarity index 98% rename from src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts rename to src/libs/Navigation/helpers/getAdaptedStateFromPath.ts index 4108a12b7253..a3f5bc3af16f 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts @@ -2,18 +2,18 @@ import type {NavigationState, PartialState, Route} from '@react-navigation/nativ import {findFocusedRoute, getStateFromPath} from '@react-navigation/native'; import pick from 'lodash/pick'; import {isAnonymousUser} from '@libs/actions/Session'; +import config from '@libs/Navigation/linkingConfig/config'; +import RELATIONS from '@libs/Navigation/linkingConfig/RELATIONS'; import type {NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; import {isFullScreenName} from '@libs/NavigationUtils'; import {extractPolicyIDFromPath, getPathWithoutPolicyID} from '@libs/PolicyUtils'; import * as ReportConnection from '@libs/ReportConnection'; -import extractPolicyIDFromQuery from '@navigation/extractPolicyIDFromQuery'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; -import config from './config'; import createSplitNavigator from './createSplitNavigator'; +import extractPolicyIDFromQuery from './extractPolicyIDFromQuery'; import getParamsFromRoute from './getParamsFromRoute'; -import RELATIONS from './RELATIONS'; import replacePathInNestedState from './replacePathInNestedState'; type GetAdaptedStateReturnType = { diff --git a/src/libs/Navigation/linkingConfig/getOnboardingAdaptedState.ts b/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts similarity index 100% rename from src/libs/Navigation/linkingConfig/getOnboardingAdaptedState.ts rename to src/libs/Navigation/helpers/getOnboardingAdaptedState.ts diff --git a/src/libs/Navigation/linkingConfig/getParamsFromRoute.ts b/src/libs/Navigation/helpers/getParamsFromRoute.ts similarity index 80% rename from src/libs/Navigation/linkingConfig/getParamsFromRoute.ts rename to src/libs/Navigation/helpers/getParamsFromRoute.ts index 0b020ddbd7bf..1dd815f65e9b 100644 --- a/src/libs/Navigation/linkingConfig/getParamsFromRoute.ts +++ b/src/libs/Navigation/helpers/getParamsFromRoute.ts @@ -1,5 +1,5 @@ +import {normalizedConfigs} from '@libs/Navigation/linkingConfig/config'; import type {Screen} from '@src/SCREENS'; -import {normalizedConfigs} from './config'; function getParamsFromRoute(screenName: string): string[] { const routeConfig = normalizedConfigs[screenName as Screen]; diff --git a/src/libs/Navigation/getPolicyIDFromState.ts b/src/libs/Navigation/helpers/getPolicyIDFromState.ts similarity index 97% rename from src/libs/Navigation/getPolicyIDFromState.ts rename to src/libs/Navigation/helpers/getPolicyIDFromState.ts index f5604c8a3733..b4b81ee15db8 100644 --- a/src/libs/Navigation/getPolicyIDFromState.ts +++ b/src/libs/Navigation/helpers/getPolicyIDFromState.ts @@ -1,7 +1,7 @@ +import type {NavigationPartialRoute, RootStackParamList, State} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import extractPolicyIDFromQuery from './extractPolicyIDFromQuery'; -import type {NavigationPartialRoute, RootStackParamList, State} from './types'; /** * returns policyID value if one exists in navigation state diff --git a/src/libs/Navigation/getStateFromPath.ts b/src/libs/Navigation/helpers/getStateFromPath.ts similarity index 93% rename from src/libs/Navigation/getStateFromPath.ts rename to src/libs/Navigation/helpers/getStateFromPath.ts index 50254bb3898d..19272ca3938f 100644 --- a/src/libs/Navigation/getStateFromPath.ts +++ b/src/libs/Navigation/helpers/getStateFromPath.ts @@ -1,7 +1,7 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; import {getStateFromPath as RNGetStateFromPath} from '@react-navigation/native'; +import linkingConfig from '@libs/Navigation/linkingConfig'; import type {Route} from '@src/ROUTES'; -import linkingConfig from './linkingConfig'; /** * @param path - The path to parse diff --git a/src/libs/Navigation/getTopmostReportParam.ts b/src/libs/Navigation/helpers/getTopmostReportParam.ts similarity index 95% rename from src/libs/Navigation/getTopmostReportParam.ts rename to src/libs/Navigation/helpers/getTopmostReportParam.ts index 30354c7c6dd0..026cd379aa1a 100644 --- a/src/libs/Navigation/getTopmostReportParam.ts +++ b/src/libs/Navigation/helpers/getTopmostReportParam.ts @@ -1,7 +1,7 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; +import type {RootStackParamList} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; -import type {RootStackParamList} from './types'; // This function is in a separate file than Navigation.ts to avoid cyclic dependency. diff --git a/src/libs/Navigation/getTopmostRouteName.ts b/src/libs/Navigation/helpers/getTopmostRouteName.ts similarity index 100% rename from src/libs/Navigation/getTopmostRouteName.ts rename to src/libs/Navigation/helpers/getTopmostRouteName.ts diff --git a/src/libs/Navigation/helpers/index.ts b/src/libs/Navigation/helpers/index.ts new file mode 100644 index 000000000000..56cc2c28611d --- /dev/null +++ b/src/libs/Navigation/helpers/index.ts @@ -0,0 +1,21 @@ +export * from './createNormalizedConfigs'; +export {default as customGetPathFromState} from './customGetPathFromState'; +export {default as getOnboardingAdaptedState} from './getOnboardingAdaptedState'; +export {default as getParamsFromRoute} from './getParamsFromRoute'; +export {default as normalizePath} from './normalizePath'; +export {default as replacePathInNestedState} from './replacePathInNestedState'; +export {default as createNormalizedConfigs} from './createNormalizedConfigs'; +export {default as createSplitNavigator} from './createSplitNavigator'; +export {default as getAdaptedStateFromPath} from './getAdaptedStateFromPath'; +export {default as extractPolicyIDFromQuery} from './extractPolicyIDFromQuery'; +export {default as closeRHPFlow} from './closeRHPFlow'; +export {default as getPolicyIDFromState} from './getPolicyIDFromState'; +export {default as getStateFromPath} from './getStateFromPath'; +export {default as getTopmostReportParam} from './getTopmostReportParam'; +export {default as getTopmostRouteName} from './getTopmostRouteName'; +export {default as isReportOpenInRHP} from './isReportOpenInRHP'; +export {default as isSearchTopmostFullScreenRoute} from './isSearchTopmostFullScreenRoute'; +export {default as isSideModalNavigator} from './isSideModalNavigator'; +export {default as setNavigationActionToMicrotaskQueue} from './setNavigationActionToMicrotaskQueue'; +export {default as shouldOpenOnAdminRoom} from './shouldOpenOnAdminRoom'; +export {default as shouldPreventDeeplinkPrompt} from './shouldPreventDeeplinkPrompt'; diff --git a/src/libs/Navigation/isReportOpenInRHP.ts b/src/libs/Navigation/helpers/isReportOpenInRHP.ts similarity index 100% rename from src/libs/Navigation/isReportOpenInRHP.ts rename to src/libs/Navigation/helpers/isReportOpenInRHP.ts diff --git a/src/libs/Navigation/isSearchTopmostFullScreenRoute.ts b/src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts similarity index 77% rename from src/libs/Navigation/isSearchTopmostFullScreenRoute.ts rename to src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts index 5599ec650c14..4991ae40a7e5 100644 --- a/src/libs/Navigation/isSearchTopmostFullScreenRoute.ts +++ b/src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts @@ -1,7 +1,7 @@ +import {navigationRef} from '@libs/Navigation/Navigation'; +import type {RootStackParamList, State} from '@libs/Navigation/types'; import {isFullScreenName} from '@libs/NavigationUtils'; import SCREENS from '@src/SCREENS'; -import {navigationRef} from './Navigation'; -import type {RootStackParamList, State} from './types'; const isSearchTopmostFullScreenRoute = (): boolean => { const rootState = navigationRef.getRootState() as State; diff --git a/src/libs/Navigation/isSideModalNavigator.ts b/src/libs/Navigation/helpers/isSideModalNavigator.ts similarity index 100% rename from src/libs/Navigation/isSideModalNavigator.ts rename to src/libs/Navigation/helpers/isSideModalNavigator.ts diff --git a/src/libs/Navigation/linkingConfig/normalizePath.ts b/src/libs/Navigation/helpers/normalizePath.ts similarity index 100% rename from src/libs/Navigation/linkingConfig/normalizePath.ts rename to src/libs/Navigation/helpers/normalizePath.ts diff --git a/src/libs/Navigation/linkingConfig/replacePathInNestedState.ts b/src/libs/Navigation/helpers/replacePathInNestedState.ts similarity index 100% rename from src/libs/Navigation/linkingConfig/replacePathInNestedState.ts rename to src/libs/Navigation/helpers/replacePathInNestedState.ts diff --git a/src/libs/Navigation/setNavigationActionToMicrotaskQueue.ts b/src/libs/Navigation/helpers/setNavigationActionToMicrotaskQueue.ts similarity index 100% rename from src/libs/Navigation/setNavigationActionToMicrotaskQueue.ts rename to src/libs/Navigation/helpers/setNavigationActionToMicrotaskQueue.ts diff --git a/src/libs/Navigation/shouldOpenOnAdminRoom.ts b/src/libs/Navigation/helpers/shouldOpenOnAdminRoom.ts similarity index 75% rename from src/libs/Navigation/shouldOpenOnAdminRoom.ts rename to src/libs/Navigation/helpers/shouldOpenOnAdminRoom.ts index a593e8c22768..ae316fa3fa44 100644 --- a/src/libs/Navigation/shouldOpenOnAdminRoom.ts +++ b/src/libs/Navigation/helpers/shouldOpenOnAdminRoom.ts @@ -1,4 +1,4 @@ -import getCurrentUrl from './currentUrl'; +import getCurrentUrl from '@libs/Navigation/currentUrl'; export default function shouldOpenOnAdminRoom() { const url = getCurrentUrl(); diff --git a/src/libs/Navigation/shouldPreventDeeplinkPrompt.ts b/src/libs/Navigation/helpers/shouldPreventDeeplinkPrompt.ts similarity index 100% rename from src/libs/Navigation/shouldPreventDeeplinkPrompt.ts rename to src/libs/Navigation/helpers/shouldPreventDeeplinkPrompt.ts diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index 9925980d37b8..26feeb8f4a85 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -1,11 +1,10 @@ import {getActionFromState} from '@react-navigation/core'; import type {NavigationContainerRef, NavigationState, PartialState, StackActionType} from '@react-navigation/native'; import {findFocusedRoute, StackActions} from '@react-navigation/native'; -import {getMatchingFullScreenRoute, isFullScreenName} from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; -import normalizePath from '@libs/Navigation/linkingConfig/normalizePath'; +import {getStateFromPath, normalizePath} from '@libs/Navigation/helpers'; +import {getMatchingFullScreenRoute, isFullScreenName} from '@libs/Navigation/helpers/getAdaptedStateFromPath'; import {shallowCompare} from '@libs/ObjectUtils'; import {extractPolicyIDFromPath, getPathWithoutPolicyID} from '@libs/PolicyUtils'; -import getStateFromPath from '@navigation/getStateFromPath'; import linkingConfig from '@navigation/linkingConfig'; import type {NavigationPartialRoute, ReportsSplitNavigatorParamList, RootStackParamList, StackNavigationAction} from '@navigation/types'; import CONST from '@src/CONST'; diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 3be3be9d15ec..252f1793af55 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -1,11 +1,11 @@ import type {LinkingOptions} from '@react-navigation/native'; +import {createNormalizedConfigs} from '@libs/Navigation/helpers'; +import type {RouteConfig} from '@libs/Navigation/helpers'; import type {RootStackParamList} from '@navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import ROUTES from '@src/ROUTES'; import type {Screen} from '@src/SCREENS'; import SCREENS from '@src/SCREENS'; -import type {RouteConfig} from './createNormalizedConfigs'; -import createNormalizedConfigs from './createNormalizedConfigs'; // Moved to a separate file to avoid cyclic dependencies. const config: LinkingOptions['config'] = { diff --git a/src/libs/Navigation/linkingConfig/index.ts b/src/libs/Navigation/linkingConfig/index.ts index 3e958d593ec9..dcdd14241cff 100644 --- a/src/libs/Navigation/linkingConfig/index.ts +++ b/src/libs/Navigation/linkingConfig/index.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ import type {LinkingOptions} from '@react-navigation/native'; +import {customGetPathFromState} from '@libs/Navigation/helpers'; +import getAdaptedStateFromPath from '@libs/Navigation/helpers/getAdaptedStateFromPath'; import type {RootStackParamList} from '@navigation/types'; import config from './config'; -import customGetPathFromState from './customGetPathFromState'; -import getAdaptedStateFromPath from './getAdaptedStateFromPath'; import prefixes from './prefixes'; const linkingConfig: LinkingOptions = { diff --git a/src/libs/ReportActionComposeFocusManager.ts b/src/libs/ReportActionComposeFocusManager.ts index 450a6d7f5481..2967a49512ea 100644 --- a/src/libs/ReportActionComposeFocusManager.ts +++ b/src/libs/ReportActionComposeFocusManager.ts @@ -2,8 +2,8 @@ import React from 'react'; import type {MutableRefObject} from 'react'; import type {TextInput} from 'react-native'; import SCREENS from '@src/SCREENS'; -import getTopmostRouteName from './Navigation/getTopmostRouteName'; -import isReportOpenInRHP from './Navigation/isReportOpenInRHP'; +import getTopmostRouteName from './Navigation/helpers/getTopmostRouteName'; +import isReportOpenInRHP from './Navigation/helpers/isReportOpenInRHP'; import navigationRef from './Navigation/navigationRef'; type FocusCallback = (shouldFocusForNonBlurInputOnTapOutside?: boolean) => void; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1ccfd4989a11..6547a7394d53 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -39,7 +39,7 @@ import GoogleTagManager from '@libs/GoogleTagManager'; import * as IOUUtils from '@libs/IOUUtils'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; import * as Localize from '@libs/Localize'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import * as NextStepUtils from '@libs/NextStepUtils'; import {rand64} from '@libs/NumberUtils'; diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index 5a1b4fc0474a..3908f372b891 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -1,8 +1,8 @@ import {findFocusedRoute, getStateFromPath} from '@react-navigation/native'; import type {NavigationState, PartialState} from '@react-navigation/native'; import Onyx from 'react-native-onyx'; +import {getAdaptedStateFromPath} from '@libs/Navigation/helpers'; import linkingConfig from '@libs/Navigation/linkingConfig'; -import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; import {navigationRef} from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; import CONST from '@src/CONST'; diff --git a/src/libs/navigateAfterOnboarding.ts b/src/libs/navigateAfterOnboarding.ts index d84927988b5c..494c70c907f4 100644 --- a/src/libs/navigateAfterOnboarding.ts +++ b/src/libs/navigateAfterOnboarding.ts @@ -1,7 +1,7 @@ import ROUTES from '@src/ROUTES'; import * as Report from './actions/Report'; +import {shouldOpenOnAdminRoom} from './Navigation/helpers'; import Navigation from './Navigation/Navigation'; -import shouldOpenOnAdminRoom from './Navigation/shouldOpenOnAdminRoom'; import * as ReportUtils from './ReportUtils'; const navigateAfterOnboarding = ( diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index be40e7f6c9e0..afa402959356 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -11,7 +11,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {EditRequestNavigatorParamList} from '@libs/Navigation/types'; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 620f4fb3dcf5..ec14c55b36a6 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -19,7 +19,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/isSearchTopmostFullScreenRoute'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 15597fb7b277..b147e28c5a77 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -32,7 +32,7 @@ import useWaitForNavigation from '@hooks/useWaitForNavigation'; import {resetExitSurveyForm} from '@libs/actions/ExitSurvey'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import BottomTabBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar'; -import getTopmostRouteName from '@libs/Navigation/getTopmostRouteName'; +import getTopmostRouteName from '@libs/Navigation/helpers/getTopmostRouteName'; import Navigation from '@libs/Navigation/Navigation'; import * as SubscriptionUtils from '@libs/SubscriptionUtils'; import * as UserUtils from '@libs/UserUtils'; diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 097891219017..952293b540b4 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -24,7 +24,7 @@ import {isConnectionInProgress} from '@libs/actions/connections'; import * as CardUtils from '@libs/CardUtils'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import BottomTabBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar'; -import getTopmostRouteName from '@libs/Navigation/getTopmostRouteName'; +import getTopmostRouteName from '@libs/Navigation/helpers/getTopmostRouteName'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; From be9cb55519ac8eb6ae4217f37f9295ac1b74d421 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 26 Nov 2024 09:19:23 +0100 Subject: [PATCH 07/26] Move navigation functions to helpers package --- .../FocusTrapForScreen/index.web.tsx | 2 +- .../ScrollOffsetContextProvider.tsx | 2 +- .../getIsScreenBlurred/index.native.ts | 2 +- .../FreezeWrapper/getIsScreenBlurred/index.ts | 2 +- .../CustomRouter.ts | 3 +-- src/libs/Navigation/Navigation.ts | 6 +++--- src/libs/Navigation/NavigationRoot.tsx | 3 +-- .../helpers/customGetPathFromState.ts | 2 +- .../helpers/getAdaptedStateFromPath.ts | 2 +- src/libs/Navigation/helpers/index.ts | 19 ++++++++++++------- .../helpers/isNavigatorName.ts} | 2 +- .../helpers/isSearchTopmostFullScreenRoute.ts | 2 +- .../{ => helpers}/linkTo/getMinimalAction.ts | 0 .../Navigation/{ => helpers}/linkTo/index.ts | 3 ++- .../Navigation/{ => helpers}/linkTo/types.ts | 0 .../index.android.ts | 0 .../setupCustomAndroidBackHandler/index.ts | 0 src/libs/ReportUtils.ts | 2 +- src/libs/actions/Report.ts | 2 +- src/pages/AddPersonalBankAccountPage.tsx | 2 +- 20 files changed, 30 insertions(+), 26 deletions(-) rename src/libs/{NavigationUtils.ts => Navigation/helpers/isNavigatorName.ts} (96%) rename src/libs/Navigation/{ => helpers}/linkTo/getMinimalAction.ts (100%) rename src/libs/Navigation/{ => helpers}/linkTo/index.ts (97%) rename src/libs/Navigation/{ => helpers}/linkTo/types.ts (100%) rename src/libs/Navigation/{ => helpers}/setupCustomAndroidBackHandler/index.android.ts (100%) rename src/libs/Navigation/{ => helpers}/setupCustomAndroidBackHandler/index.ts (100%) diff --git a/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx b/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx index 62a6b5d100a8..2a5fb850066c 100644 --- a/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx +++ b/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx @@ -5,7 +5,7 @@ import sharedTrapStack from '@components/FocusTrap/sharedTrapStack'; import TOP_TAB_SCREENS from '@components/FocusTrap/TOP_TAB_SCREENS'; import WIDE_LAYOUT_INACTIVE_SCREENS from '@components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; -import {isSidebarScreenName} from '@libs/NavigationUtils'; +import {isSidebarScreenName} from '@libs/Navigation/helpers'; import CONST from '@src/CONST'; import type FocusTrapProps from './FocusTrapProps'; diff --git a/src/components/ScrollOffsetContextProvider.tsx b/src/components/ScrollOffsetContextProvider.tsx index f5573fd6b2e4..9620da9e72e5 100644 --- a/src/components/ScrollOffsetContextProvider.tsx +++ b/src/components/ScrollOffsetContextProvider.tsx @@ -2,9 +2,9 @@ import type {ParamListBase} from '@react-navigation/native'; import React, {createContext, useCallback, useEffect, useMemo, useRef} from 'react'; import {withOnyx} from 'react-native-onyx'; import usePrevious from '@hooks/usePrevious'; +import {isSidebarScreenName} from '@libs/Navigation/helpers'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {NavigationPartialRoute, State} from '@libs/Navigation/types'; -import {isSidebarScreenName} from '@libs/NavigationUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; import type {PriorityMode} from '@src/types/onyx'; diff --git a/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.native.ts b/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.native.ts index 9b1cbd94dced..4cc3caa86cdb 100644 --- a/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.native.ts +++ b/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.native.ts @@ -1,5 +1,5 @@ import type {NavigationState} from '@react-navigation/native'; -import {isFullScreenName} from '@libs/NavigationUtils'; +import {isFullScreenName} from '@libs/Navigation/helpers'; function getIsScreenBlurred(state: NavigationState, currentRouteKey: string) { // If the screen is one of the last two fullscreen routes in the stack, it is not freezed on native platforms. diff --git a/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.ts b/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.ts index beae98460c1a..4ad2ea2c9aa5 100644 --- a/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.ts +++ b/src/libs/Navigation/AppNavigator/FreezeWrapper/getIsScreenBlurred/index.ts @@ -1,5 +1,5 @@ import type {NavigationState} from '@react-navigation/native'; -import {isFullScreenName} from '@libs/NavigationUtils'; +import {isFullScreenName} from '@libs/Navigation/helpers'; function getIsScreenBlurred(state: NavigationState, currentRouteKey: string) { const lastFullScreenRoute = state.routes.findLast((route) => isFullScreenName(route.name)); diff --git a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts index ae3815e91997..94bb91fb5434 100644 --- a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts @@ -3,8 +3,7 @@ import {findFocusedRoute, StackRouter} from '@react-navigation/native'; import type {ParamListBase} from '@react-navigation/routers'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; import * as Localize from '@libs/Localize'; -import {isSideModalNavigator} from '@libs/Navigation/helpers'; -import {isOnboardingFlowName} from '@libs/NavigationUtils'; +import {isOnboardingFlowName, isSideModalNavigator} from '@libs/Navigation/helpers'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index b1d32c5f6016..48229b9a2ef4 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -7,7 +7,6 @@ import type {OnyxEntry} from 'react-native-onyx'; import type {Writable} from 'type-fest'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import Log from '@libs/Log'; -import {isSplitNavigatorName} from '@libs/NavigationUtils'; import {shallowCompare} from '@libs/ObjectUtils'; import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils'; import * as ReportConnection from '@libs/ReportConnection'; @@ -22,17 +21,18 @@ import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import { createSplitNavigator, + getMinimalAction, getPolicyIDFromState, getStateFromPath, getTopmostReportParam, isReportOpenInRHP, + isSplitNavigatorName, + linkTo, closeRHPFlow as originalCloseRHPFlow, setNavigationActionToMicrotaskQueue, } from './helpers'; import linkingConfig from './linkingConfig'; import RELATIONS from './linkingConfig/RELATIONS'; -import linkTo from './linkTo'; -import getMinimalAction from './linkTo/getMinimalAction'; import navigationRef from './navigationRef'; import type {NavigationPartialRoute, NavigationStateRoute, RootStackParamList, State} from './types'; diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 99723d3422a9..3181e2d60979 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -23,10 +23,9 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import AppNavigator from './AppNavigator'; import {cleanPreservedSplitNavigatorStates} from './AppNavigator/createSplitStackNavigator/usePreserveSplitNavigatorState'; -import {customGetPathFromState, getAdaptedStateFromPath} from './helpers'; +import {customGetPathFromState, getAdaptedStateFromPath, setupCustomAndroidBackHandler} from './helpers'; import linkingConfig from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; -import setupCustomAndroidBackHandler from './setupCustomAndroidBackHandler'; type NavigationRootProps = { /** Whether the current user is logged in with an authToken */ diff --git a/src/libs/Navigation/helpers/customGetPathFromState.ts b/src/libs/Navigation/helpers/customGetPathFromState.ts index 8954e48955f8..0a42aa67a1ce 100644 --- a/src/libs/Navigation/helpers/customGetPathFromState.ts +++ b/src/libs/Navigation/helpers/customGetPathFromState.ts @@ -1,6 +1,6 @@ import {getPathFromState} from '@react-navigation/native'; -import {isFullScreenName} from '@libs/NavigationUtils'; import NAVIGATORS from '@src/NAVIGATORS'; +import {isFullScreenName} from './isNavigatorName'; const customGetPathFromState: typeof getPathFromState = (state, options) => { const path = getPathFromState(state, options); diff --git a/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts index a3f5bc3af16f..7122bc8b75e0 100644 --- a/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts @@ -5,7 +5,6 @@ import {isAnonymousUser} from '@libs/actions/Session'; import config from '@libs/Navigation/linkingConfig/config'; import RELATIONS from '@libs/Navigation/linkingConfig/RELATIONS'; import type {NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; -import {isFullScreenName} from '@libs/NavigationUtils'; import {extractPolicyIDFromPath, getPathWithoutPolicyID} from '@libs/PolicyUtils'; import * as ReportConnection from '@libs/ReportConnection'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -14,6 +13,7 @@ import SCREENS from '@src/SCREENS'; import createSplitNavigator from './createSplitNavigator'; import extractPolicyIDFromQuery from './extractPolicyIDFromQuery'; import getParamsFromRoute from './getParamsFromRoute'; +import {isFullScreenName} from './isNavigatorName'; import replacePathInNestedState from './replacePathInNestedState'; type GetAdaptedStateReturnType = { diff --git a/src/libs/Navigation/helpers/index.ts b/src/libs/Navigation/helpers/index.ts index 56cc2c28611d..46a977002326 100644 --- a/src/libs/Navigation/helpers/index.ts +++ b/src/libs/Navigation/helpers/index.ts @@ -1,14 +1,14 @@ export * from './createNormalizedConfigs'; -export {default as customGetPathFromState} from './customGetPathFromState'; -export {default as getOnboardingAdaptedState} from './getOnboardingAdaptedState'; -export {default as getParamsFromRoute} from './getParamsFromRoute'; -export {default as normalizePath} from './normalizePath'; -export {default as replacePathInNestedState} from './replacePathInNestedState'; +export * from './isNavigatorName'; +export * from './linkTo/types'; +export {default as closeRHPFlow} from './closeRHPFlow'; export {default as createNormalizedConfigs} from './createNormalizedConfigs'; export {default as createSplitNavigator} from './createSplitNavigator'; -export {default as getAdaptedStateFromPath} from './getAdaptedStateFromPath'; +export {default as customGetPathFromState} from './customGetPathFromState'; export {default as extractPolicyIDFromQuery} from './extractPolicyIDFromQuery'; -export {default as closeRHPFlow} from './closeRHPFlow'; +export {default as getAdaptedStateFromPath} from './getAdaptedStateFromPath'; +export {default as getOnboardingAdaptedState} from './getOnboardingAdaptedState'; +export {default as getParamsFromRoute} from './getParamsFromRoute'; export {default as getPolicyIDFromState} from './getPolicyIDFromState'; export {default as getStateFromPath} from './getStateFromPath'; export {default as getTopmostReportParam} from './getTopmostReportParam'; @@ -16,6 +16,11 @@ export {default as getTopmostRouteName} from './getTopmostRouteName'; export {default as isReportOpenInRHP} from './isReportOpenInRHP'; export {default as isSearchTopmostFullScreenRoute} from './isSearchTopmostFullScreenRoute'; export {default as isSideModalNavigator} from './isSideModalNavigator'; +export {default as linkTo} from './linkTo'; +export {default as getMinimalAction} from './linkTo/getMinimalAction'; +export {default as normalizePath} from './normalizePath'; +export {default as replacePathInNestedState} from './replacePathInNestedState'; export {default as setNavigationActionToMicrotaskQueue} from './setNavigationActionToMicrotaskQueue'; +export {default as setupCustomAndroidBackHandler} from './setupCustomAndroidBackHandler'; export {default as shouldOpenOnAdminRoom} from './shouldOpenOnAdminRoom'; export {default as shouldPreventDeeplinkPrompt} from './shouldPreventDeeplinkPrompt'; diff --git a/src/libs/NavigationUtils.ts b/src/libs/Navigation/helpers/isNavigatorName.ts similarity index 96% rename from src/libs/NavigationUtils.ts rename to src/libs/Navigation/helpers/isNavigatorName.ts index 6ec44e62d690..49bada1dc286 100644 --- a/src/libs/NavigationUtils.ts +++ b/src/libs/Navigation/helpers/isNavigatorName.ts @@ -1,6 +1,6 @@ +import type {FullScreenName, OnboardingFlowName, SplitNavigatorLHNScreen, SplitNavigatorName} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; -import type {FullScreenName, OnboardingFlowName, SplitNavigatorLHNScreen, SplitNavigatorName} from './Navigation/types'; const SPLIT_NAVIGATORS = [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]; const FULL_SCREENS = [...SPLIT_NAVIGATORS, SCREENS.SEARCH.CENTRAL_PANE]; diff --git a/src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts b/src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts index 4991ae40a7e5..e98b253b74bd 100644 --- a/src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts +++ b/src/libs/Navigation/helpers/isSearchTopmostFullScreenRoute.ts @@ -1,7 +1,7 @@ import {navigationRef} from '@libs/Navigation/Navigation'; import type {RootStackParamList, State} from '@libs/Navigation/types'; -import {isFullScreenName} from '@libs/NavigationUtils'; import SCREENS from '@src/SCREENS'; +import {isFullScreenName} from './isNavigatorName'; const isSearchTopmostFullScreenRoute = (): boolean => { const rootState = navigationRef.getRootState() as State; diff --git a/src/libs/Navigation/linkTo/getMinimalAction.ts b/src/libs/Navigation/helpers/linkTo/getMinimalAction.ts similarity index 100% rename from src/libs/Navigation/linkTo/getMinimalAction.ts rename to src/libs/Navigation/helpers/linkTo/getMinimalAction.ts diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/helpers/linkTo/index.ts similarity index 97% rename from src/libs/Navigation/linkTo/index.ts rename to src/libs/Navigation/helpers/linkTo/index.ts index 26feeb8f4a85..39dd6b0b1571 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/helpers/linkTo/index.ts @@ -1,8 +1,9 @@ import {getActionFromState} from '@react-navigation/core'; import type {NavigationContainerRef, NavigationState, PartialState, StackActionType} from '@react-navigation/native'; import {findFocusedRoute, StackActions} from '@react-navigation/native'; -import {getStateFromPath, normalizePath} from '@libs/Navigation/helpers'; import {getMatchingFullScreenRoute, isFullScreenName} from '@libs/Navigation/helpers/getAdaptedStateFromPath'; +import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath'; +import normalizePath from '@libs/Navigation/helpers/normalizePath'; import {shallowCompare} from '@libs/ObjectUtils'; import {extractPolicyIDFromPath, getPathWithoutPolicyID} from '@libs/PolicyUtils'; import linkingConfig from '@navigation/linkingConfig'; diff --git a/src/libs/Navigation/linkTo/types.ts b/src/libs/Navigation/helpers/linkTo/types.ts similarity index 100% rename from src/libs/Navigation/linkTo/types.ts rename to src/libs/Navigation/helpers/linkTo/types.ts diff --git a/src/libs/Navigation/setupCustomAndroidBackHandler/index.android.ts b/src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.android.ts similarity index 100% rename from src/libs/Navigation/setupCustomAndroidBackHandler/index.android.ts rename to src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.android.ts diff --git a/src/libs/Navigation/setupCustomAndroidBackHandler/index.ts b/src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.ts similarity index 100% rename from src/libs/Navigation/setupCustomAndroidBackHandler/index.ts rename to src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.ts diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2179799c788b..fdc4fc712de2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -74,9 +74,9 @@ import * as Localize from './Localize'; import Log from './Log'; import {isEmailPublicDomain} from './LoginUtils'; import ModifiedExpenseMessage from './ModifiedExpenseMessage'; +import {isFullScreenName} from './Navigation/helpers/isNavigatorName'; import linkingConfig from './Navigation/linkingConfig'; import Navigation, {navigationRef} from './Navigation/Navigation'; -import {isFullScreenName} from './NavigationUtils'; import * as NumberUtils from './NumberUtils'; import Parser from './Parser'; import Permissions from './Permissions'; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 5be8ed0a0eed..40d62d5d5559 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -67,8 +67,8 @@ import isPublicScreenRoute from '@libs/isPublicScreenRoute'; import * as Localize from '@libs/Localize'; import Log from '@libs/Log'; import {registerPaginationConfig} from '@libs/Middleware/Pagination'; +import {isOnboardingFlowName} from '@libs/Navigation/helpers'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; -import {isOnboardingFlowName} from '@libs/NavigationUtils'; import enhanceParameters from '@libs/Network/enhanceParameters'; import type {NetworkStatus} from '@libs/NetworkConnection'; import LocalNotification from '@libs/Notification/LocalNotification'; diff --git a/src/pages/AddPersonalBankAccountPage.tsx b/src/pages/AddPersonalBankAccountPage.tsx index cd8d3817c927..8c7ba7e9af14 100644 --- a/src/pages/AddPersonalBankAccountPage.tsx +++ b/src/pages/AddPersonalBankAccountPage.tsx @@ -10,8 +10,8 @@ import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import getPlaidOAuthReceivedRedirectURI from '@libs/getPlaidOAuthReceivedRedirectURI'; +import {isFullScreenName} from '@libs/Navigation/helpers'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; -import {isFullScreenName} from '@libs/NavigationUtils'; import * as BankAccounts from '@userActions/BankAccounts'; import * as PaymentMethods from '@userActions/PaymentMethods'; import NAVIGATORS from '@src/NAVIGATORS'; From e8749f4ddf816ae804323eaa50e143392d8c552c Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 26 Nov 2024 14:42:59 +0100 Subject: [PATCH 08/26] Make goUp private --- src/libs/Navigation/Navigation.ts | 16 ++++++++++------ src/pages/home/sidebar/BottomTabAvatar.tsx | 4 ++-- .../request/step/IOURequestStepConfirmation.tsx | 2 +- .../PersonalDetails/CountrySelectionPage.tsx | 2 +- .../PersonalDetails/StateSelectionPage.tsx | 2 +- .../Subscription/CardSection/CardSection.tsx | 2 +- src/pages/workspace/AccessOrNotFoundWrapper.tsx | 2 +- src/pages/workspace/WorkspaceInitialPage.tsx | 6 +++--- .../workspace/WorkspacePageWithSections.tsx | 4 ++-- src/pages/workspace/WorkspacesListPage.tsx | 4 ++-- .../expensifyCard/issueNew/ConfirmationStep.tsx | 2 +- 11 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 48229b9a2ef4..9f3eeb43aedf 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -186,23 +186,26 @@ function doesRouteMatchToMinimalActionPayload(route: NavigationStateRoute | Navi return shallowCompare(routeParams, minimalActionParams); } -type GoUpOptions = { +type GoBackOptions = { /** If we should compare params when searching for a route in state to go up to. * There are situations where we want to compare params when going up e.g. goUp to a specific report. * Sometimes we want to go up and update params of screen e.g. country picker. * In that case we want to goUp to a country picker with any params so we don't compare them. */ compareParams?: boolean; + + shouldPopToTop?: boolean; }; -const defaultGoUpOptions: Required = { +const defaultGoUpOptions: Required = { compareParams: true, + shouldPopToTop: false, }; function isRootNavigatorState(state: State): state is State { return state.key === navigationRef.current?.getRootState().key; } -function goUp(fallbackRoute: Route, options?: GoUpOptions) { +function goUp(fallbackRoute: Route, options?: GoBackOptions) { const compareParams = options?.compareParams ?? defaultGoUpOptions.compareParams; if (!canNavigate('goBack')) { @@ -253,11 +256,13 @@ function goUp(fallbackRoute: Route, options?: GoUpOptions) { * @param fallbackRoute - Fallback route if pop/goBack action should, but is not possible within RHP * @param shouldPopToTop - Should we navigate to LHN on back press */ -function goBack(fallbackRoute?: Route, shouldPopToTop = false) { +function goBack(fallbackRoute?: Route, options?: GoBackOptions) { if (!canNavigate('goBack')) { return; } + const shouldPopToTop = options?.shouldPopToTop ?? false; + if (shouldPopToTop) { if (shouldPopAllStateOnUP) { shouldPopAllStateOnUP = false; @@ -267,7 +272,7 @@ function goBack(fallbackRoute?: Route, shouldPopToTop = false) { } if (fallbackRoute) { - goUp(fallbackRoute); + goUp(fallbackRoute, options); return; } @@ -485,7 +490,6 @@ export default { closeRHPFlow, setNavigationActionToMicrotaskQueue, navigateToReportWithPolicyCheck, - goUp, }; export {navigationRef}; diff --git a/src/pages/home/sidebar/BottomTabAvatar.tsx b/src/pages/home/sidebar/BottomTabAvatar.tsx index 631287f544a8..0d93b3ff5a87 100644 --- a/src/pages/home/sidebar/BottomTabAvatar.tsx +++ b/src/pages/home/sidebar/BottomTabAvatar.tsx @@ -45,12 +45,12 @@ function BottomTabAvatar({isCreateMenuOpen = false, isSelected = false}: BottomT } if (route.name === SCREENS.SETTINGS.WORKSPACES && shouldUseNarrowLayout) { - Navigation.goUp(ROUTES.SETTINGS); + Navigation.goBack(ROUTES.SETTINGS); return; } if (route.name === SCREENS.WORKSPACE.INITIAL) { - Navigation.goUp(ROUTES.SETTINGS); + Navigation.goBack(ROUTES.SETTINGS); if (shouldUseNarrowLayout) { Navigation.navigate(ROUTES.SETTINGS, CONST.NAVIGATION.ACTION_TYPE.REPLACE); } diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index ccdbe7ebdf29..ab1f27f163f9 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -184,7 +184,7 @@ function IOURequestStepConfirmation({ // back to the participants step if (!transaction?.participantsAutoAssigned && participantsAutoAssignedFromRoute !== 'true') { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - Navigation.goUp(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action), {compareParams: false}); + Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action), {compareParams: false}); return; } IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action); diff --git a/src/pages/settings/Profile/PersonalDetails/CountrySelectionPage.tsx b/src/pages/settings/Profile/PersonalDetails/CountrySelectionPage.tsx index 28af0b5d4364..303ffa1c9967 100644 --- a/src/pages/settings/Profile/PersonalDetails/CountrySelectionPage.tsx +++ b/src/pages/settings/Profile/PersonalDetails/CountrySelectionPage.tsx @@ -50,7 +50,7 @@ function CountrySelectionPage({route}: CountrySelectionPageProps) { Navigation.goBack(); } else { // Set compareParams to false because we want to goUp to this particular screen and update params (country). - Navigation.goUp(appendParam(backTo, 'country', option.value), {compareParams: false}); + Navigation.goBack(appendParam(backTo, 'country', option.value), {compareParams: false}); } }, [route], diff --git a/src/pages/settings/Profile/PersonalDetails/StateSelectionPage.tsx b/src/pages/settings/Profile/PersonalDetails/StateSelectionPage.tsx index 390b48f0d995..14a3248d2c80 100644 --- a/src/pages/settings/Profile/PersonalDetails/StateSelectionPage.tsx +++ b/src/pages/settings/Profile/PersonalDetails/StateSelectionPage.tsx @@ -60,7 +60,7 @@ function StateSelectionPage() { Navigation.goBack(); } else { // Set compareParams to false because we want to goUp to this particular screen and update params (state). - Navigation.goUp(appendParam(backTo, 'state', option.value), {compareParams: false}); + Navigation.goBack(appendParam(backTo, 'state', option.value), {compareParams: false}); } }, [params?.backTo], diff --git a/src/pages/settings/Subscription/CardSection/CardSection.tsx b/src/pages/settings/Subscription/CardSection/CardSection.tsx index 947a2d10f777..80381a345ff9 100644 --- a/src/pages/settings/Subscription/CardSection/CardSection.tsx +++ b/src/pages/settings/Subscription/CardSection/CardSection.tsx @@ -57,7 +57,7 @@ function CardSection() { const requestRefund = useCallback(() => { User.requestRefund(); setIsRequestRefundModalVisible(false); - Navigation.goUp(ROUTES.HOME); + Navigation.goBack(ROUTES.HOME); }, []); const viewPurchases = useCallback(() => { diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index 83a24e2084d3..39ac7b2f9451 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -98,7 +98,7 @@ function PageNotFoundFallback({policyID, fullPageNotFoundViewProps, isFeatureEna shouldForceFullScreen={shouldShowFullScreenFallback} onBackButtonPress={() => { if (isPolicyNotAccessible) { - Navigation.goUp(ROUTES.SETTINGS_WORKSPACES); + Navigation.goBack(ROUTES.SETTINGS_WORKSPACES); return; } Navigation.goBack(policyID && !isMoneyRequest ? ROUTES.WORKSPACE_PROFILE.getRoute(policyID) : undefined); diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 952293b540b4..a858f42a7e6e 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -398,7 +398,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac > Navigation.goUp(ROUTES.HOME)} + onLinkPress={() => Navigation.goBack(ROUTES.HOME)} shouldShow={shouldShowNotFoundPage} subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined} > @@ -406,10 +406,10 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac title={policyName} onBackButtonPress={() => { if (route.params?.backTo) { - Navigation.goUp(ROUTES.HOME); + Navigation.goBack(ROUTES.HOME); Navigation.isNavigationReady().then(() => Navigation.navigate(route.params?.backTo as Route)); } else { - Navigation.goUp(ROUTES.SETTINGS_WORKSPACES); + Navigation.goBack(ROUTES.SETTINGS_WORKSPACES); } }} policyAvatar={policyAvatar} diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx index 6ebe98d0bef6..a74c9fcef02a 100644 --- a/src/pages/workspace/WorkspacePageWithSections.tsx +++ b/src/pages/workspace/WorkspacePageWithSections.tsx @@ -174,8 +174,8 @@ function WorkspacePageWithSections({ shouldShowOfflineIndicatorInWideScreen={shouldShowOfflineIndicatorInWideScreen && !shouldShow} > Navigation.goUp(ROUTES.SETTINGS_WORKSPACES)} - onLinkPress={() => Navigation.goUp(ROUTES.HOME)} + onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)} + onLinkPress={() => Navigation.goBack(ROUTES.HOME)} shouldShow={shouldShow} subtitleKey={shouldShowPolicy ? 'workspace.common.notAuthorized' : undefined} shouldForceFullScreen diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 4db55d08b290..17e9800f2924 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -395,7 +395,7 @@ function WorkspacesListPage() { title={translate('common.workspaces')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goUp(ROUTES.SETTINGS)} + onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)} icon={Illustrations.BigRocket} /> @@ -430,7 +430,7 @@ function WorkspacesListPage() { title={translate('common.workspaces')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goUp(ROUTES.SETTINGS)} + onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)} icon={Illustrations.BigRocket} > {!shouldUseNarrowLayout && getHeaderButton()} diff --git a/src/pages/workspace/expensifyCard/issueNew/ConfirmationStep.tsx b/src/pages/workspace/expensifyCard/issueNew/ConfirmationStep.tsx index 0b574c64c673..f168f0617af1 100644 --- a/src/pages/workspace/expensifyCard/issueNew/ConfirmationStep.tsx +++ b/src/pages/workspace/expensifyCard/issueNew/ConfirmationStep.tsx @@ -57,7 +57,7 @@ function ConfirmationStep({policyID, backTo}: ConfirmationStepProps) { if (!isSuccessful) { return; } - Navigation.goUp(backTo ?? ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID ?? '-1')); + Navigation.goBack(backTo ?? ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID ?? '-1')); Card.clearIssueNewCardFlow(); }, [backTo, policyID, isSuccessful]); From 3ed172efa7c67f630bff8cb881184c9d18b0d8b1 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 26 Nov 2024 15:01:26 +0100 Subject: [PATCH 09/26] Rename SplitNavigatorLHNScreen to SplitNavigatorSidebarScreen --- src/libs/Navigation/helpers/createSplitNavigator.ts | 6 +++--- src/libs/Navigation/helpers/isNavigatorName.ts | 4 ++-- .../Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts | 6 +++--- .../linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts | 4 ++-- src/libs/Navigation/types.ts | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libs/Navigation/helpers/createSplitNavigator.ts b/src/libs/Navigation/helpers/createSplitNavigator.ts index a43e5a83d7ab..8ceb765b9922 100644 --- a/src/libs/Navigation/helpers/createSplitNavigator.ts +++ b/src/libs/Navigation/helpers/createSplitNavigator.ts @@ -1,13 +1,13 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; import LHN_TO_SPLIT_NAVIGATOR_NAME from '@libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING'; -import type {NavigationPartialRoute, SplitNavigatorByLHN, SplitNavigatorLHNScreen, SplitNavigatorParamListType} from '@libs/Navigation/types'; +import type {NavigationPartialRoute, SplitNavigatorByLHN, SplitNavigatorParamListType, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; -type ExtractRouteType = Extract; +type ExtractRouteType = Extract; // The function getPathFromState that we are using in some places isn't working correctly without defined index. const getRoutesWithIndex = (routes: NavigationPartialRoute[]): PartialState => ({routes, index: routes.length - 1}); -function createSplitNavigator( +function createSplitNavigator( splitNavigatorLHN: NavigationPartialRoute, route?: NavigationPartialRoute>, splitNavigatorParams?: Record, diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index 49bada1dc286..ae5118b9833e 100644 --- a/src/libs/Navigation/helpers/isNavigatorName.ts +++ b/src/libs/Navigation/helpers/isNavigatorName.ts @@ -1,4 +1,4 @@ -import type {FullScreenName, OnboardingFlowName, SplitNavigatorLHNScreen, SplitNavigatorName} from '@libs/Navigation/types'; +import type {FullScreenName, OnboardingFlowName, SplitNavigatorName, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; @@ -39,7 +39,7 @@ function isFullScreenName(screen: string | undefined) { } function isSidebarScreenName(screen: string | undefined) { - return checkIfScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); + return checkIfScreenHasMatchingNameToSetValues(screen, SIDEBARS_SET); } export {isFullScreenName, isOnboardingFlowName, isSidebarScreenName, isSplitNavigatorName}; diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts index a07ef3b8b9ac..1923b50b4ea2 100644 --- a/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts @@ -1,9 +1,9 @@ -import type {SplitNavigatorLHNScreen} from '@libs/Navigation/types'; +import type {SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; -// This file is used to define the relationship between the sidebar (LHN) and the right hand pane (RHP) screen. +// This file is used to define the relationship between the sidebar and the right hand pane (RHP) screen. // These screens don't care about the split navigator's central screen and are in relation directly to the sidebar. -const SIDEBAR_TO_RHP: Partial> = { +const SIDEBAR_TO_RHP: Partial> = { [SCREENS.SETTINGS.ROOT]: [ SCREENS.SETTINGS.SHARE_CODE, SCREENS.SETTINGS.PROFILE.STATUS, diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts b/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts index 943552f929b8..d5c1b6089812 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts @@ -1,8 +1,8 @@ // @TODO Remove this file before merging to the main. -import type {SplitNavigatorLHNScreen, SplitNavigatorScreenName} from '@navigation/types'; +import type {SplitNavigatorScreenName, SplitNavigatorSidebarScreen} from '@navigation/types'; import SCREENS from '@src/SCREENS'; -const TAB_TO_CENTRAL_PANE_MAPPING: Record = { +const TAB_TO_CENTRAL_PANE_MAPPING: Record = { [SCREENS.HOME]: [SCREENS.REPORT], [SCREENS.SETTINGS.ROOT]: [ SCREENS.SETTINGS.PROFILE.ROOT, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 304aa93c13f0..9483ae20274e 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -53,7 +53,7 @@ type NavigationPartialRoute = PartialRoute = NavigationState | PartialState>; -type SplitNavigatorLHNScreen = keyof typeof LHN_TO_SPLIT_NAVIGATOR_NAME; +type SplitNavigatorSidebarScreen = keyof typeof LHN_TO_SPLIT_NAVIGATOR_NAME; type SplitNavigatorParamListType = { [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SettingsSplitNavigatorParamList; @@ -61,7 +61,7 @@ type SplitNavigatorParamListType = { [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: WorkspaceSplitNavigatorParamList; }; -type SplitNavigatorByLHN = (typeof LHN_TO_SPLIT_NAVIGATOR_NAME)[T]; +type SplitNavigatorByLHN = (typeof LHN_TO_SPLIT_NAVIGATOR_NAME)[T]; type CentralPaneScreensParamList = { [SCREENS.REPORT]: { @@ -1810,7 +1810,7 @@ export type { SplitNavigatorName, SplitNavigatorScreenName, FullScreenName, - SplitNavigatorLHNScreen, + SplitNavigatorSidebarScreen, SplitNavigatorParamListType, SplitNavigatorByLHN, }; From dd7a57c17015c96d969315eee95e205f4ae0e6bf Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 26 Nov 2024 15:39:17 +0100 Subject: [PATCH 10/26] Rename createSplitNavigator to getInitialSplitNavigatorState --- .../getInitialSplitNavigatorState.ts} | 4 ++-- src/libs/Navigation/Navigation.ts | 4 ++-- src/libs/Navigation/helpers/getAdaptedStateFromPath.ts | 10 +++++----- src/libs/Navigation/helpers/index.ts | 1 - 4 files changed, 9 insertions(+), 10 deletions(-) rename src/libs/Navigation/{helpers/createSplitNavigator.ts => AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts} (90%) diff --git a/src/libs/Navigation/helpers/createSplitNavigator.ts b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts similarity index 90% rename from src/libs/Navigation/helpers/createSplitNavigator.ts rename to src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts index 8ceb765b9922..de272f67d926 100644 --- a/src/libs/Navigation/helpers/createSplitNavigator.ts +++ b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts @@ -7,7 +7,7 @@ type ExtractRouteType = Extract => ({routes, index: routes.length - 1}); -function createSplitNavigator( +function getInitialSplitNavigatorState( splitNavigatorLHN: NavigationPartialRoute, route?: NavigationPartialRoute>, splitNavigatorParams?: Record, @@ -26,4 +26,4 @@ function createSplitNavigator( }; } -export default createSplitNavigator; +export default getInitialSplitNavigatorState; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 9f3eeb43aedf..2f682112ee9d 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -19,8 +19,8 @@ import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES'; import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import getInitialSplitNavigatorState from './AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState'; import { - createSplitNavigator, getMinimalAction, getPolicyIDFromState, getStateFromPath, @@ -314,7 +314,7 @@ function resetToHome() { name: SCREENS.REPORT, } : undefined; - const payload = createSplitNavigator({name: SCREENS.HOME}, splitNavigatorMainScreen); + const payload = getInitialSplitNavigatorState({name: SCREENS.HOME}, splitNavigatorMainScreen); navigationRef.dispatch({payload, type: 'REPLACE', target: rootState.key}); } diff --git a/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts index 7122bc8b75e0..c7a712f0fd7a 100644 --- a/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts @@ -2,6 +2,7 @@ import type {NavigationState, PartialState, Route} from '@react-navigation/nativ import {findFocusedRoute, getStateFromPath} from '@react-navigation/native'; import pick from 'lodash/pick'; import {isAnonymousUser} from '@libs/actions/Session'; +import getInitialSplitNavigatorState from '@libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState'; import config from '@libs/Navigation/linkingConfig/config'; import RELATIONS from '@libs/Navigation/linkingConfig/RELATIONS'; import type {NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; @@ -10,7 +11,6 @@ import * as ReportConnection from '@libs/ReportConnection'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; -import createSplitNavigator from './createSplitNavigator'; import extractPolicyIDFromQuery from './extractPolicyIDFromQuery'; import getParamsFromRoute from './getParamsFromRoute'; import {isFullScreenName} from './isNavigatorName'; @@ -70,7 +70,7 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st } if (RELATIONS.RHP_TO_SIDEBAR[route.name]) { - return createSplitNavigator( + return getInitialSplitNavigatorState( { name: RELATIONS.RHP_TO_SIDEBAR[route.name], }, @@ -82,7 +82,7 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st if (RELATIONS.RHP_TO_WORKSPACE[route.name]) { const paramsFromRoute = getParamsFromRoute(RELATIONS.RHP_TO_WORKSPACE[route.name]); - return createSplitNavigator( + return getInitialSplitNavigatorState( { name: SCREENS.WORKSPACE.INITIAL, params: paramsFromRoute.length > 0 ? pick(route.params, paramsFromRoute) : undefined, @@ -97,7 +97,7 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st if (RELATIONS.RHP_TO_SETTINGS[route.name]) { const paramsFromRoute = getParamsFromRoute(RELATIONS.RHP_TO_SETTINGS[route.name]); - return createSplitNavigator( + return getInitialSplitNavigatorState( { name: SCREENS.SETTINGS.ROOT, }, @@ -128,7 +128,7 @@ function getDefaultFullScreenRoute(route?: NavigationPartialRoute, policyID?: st return fallbackRoute; } - return createSplitNavigator( + return getInitialSplitNavigatorState( { name: SCREENS.HOME, }, diff --git a/src/libs/Navigation/helpers/index.ts b/src/libs/Navigation/helpers/index.ts index 46a977002326..d3756c09b877 100644 --- a/src/libs/Navigation/helpers/index.ts +++ b/src/libs/Navigation/helpers/index.ts @@ -3,7 +3,6 @@ export * from './isNavigatorName'; export * from './linkTo/types'; export {default as closeRHPFlow} from './closeRHPFlow'; export {default as createNormalizedConfigs} from './createNormalizedConfigs'; -export {default as createSplitNavigator} from './createSplitNavigator'; export {default as customGetPathFromState} from './customGetPathFromState'; export {default as extractPolicyIDFromQuery} from './extractPolicyIDFromQuery'; export {default as getAdaptedStateFromPath} from './getAdaptedStateFromPath'; From 2afede2b8fb6fd39ae493a64a2175cc6e932b811 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 26 Nov 2024 15:48:00 +0100 Subject: [PATCH 11/26] Fix goBack calls with shouldPopToTop --- src/libs/actions/Report.ts | 2 +- src/libs/navigateAfterJoinRequest/index.desktop.ts | 2 +- src/libs/navigateAfterJoinRequest/index.ts | 2 +- src/libs/navigateAfterJoinRequest/index.web.ts | 2 +- src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx | 4 ++-- src/pages/EnablePayments/EnablePayments.tsx | 2 +- src/pages/home/ReportScreen.tsx | 4 ++-- src/pages/workspace/WorkspaceJoinUserPage.tsx | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 40d62d5d5559..e62891dba5cb 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2422,7 +2422,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string, shouldPopToTop Navigation.setShouldPopAllStateOnUP(true); } // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, shouldPopToTop); + Navigation.goBack(undefined, {shouldPopToTop}); navigateToConciergeChat(); InteractionManager.runAfterInteractions(() => { deleteReport(reportID, shouldDeleteChildReports); diff --git a/src/libs/navigateAfterJoinRequest/index.desktop.ts b/src/libs/navigateAfterJoinRequest/index.desktop.ts index 15ebdca70a44..9b72ee30de57 100644 --- a/src/libs/navigateAfterJoinRequest/index.desktop.ts +++ b/src/libs/navigateAfterJoinRequest/index.desktop.ts @@ -4,7 +4,7 @@ import ROUTES from '@src/ROUTES'; const navigateAfterJoinRequest = () => { // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, true); + Navigation.goBack(undefined, {shouldPopToTop: true}); if (getIsSmallScreenWidth()) { Navigation.navigate(ROUTES.SETTINGS); } diff --git a/src/libs/navigateAfterJoinRequest/index.ts b/src/libs/navigateAfterJoinRequest/index.ts index 0425f52c1e56..a3ac50cd59be 100644 --- a/src/libs/navigateAfterJoinRequest/index.ts +++ b/src/libs/navigateAfterJoinRequest/index.ts @@ -3,7 +3,7 @@ import ROUTES from '@src/ROUTES'; const navigateAfterJoinRequest = () => { // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, true); + Navigation.goBack(undefined, {shouldPopToTop: true}); Navigation.navigate(ROUTES.SETTINGS); Navigation.navigate(ROUTES.SETTINGS_WORKSPACES); }; diff --git a/src/libs/navigateAfterJoinRequest/index.web.ts b/src/libs/navigateAfterJoinRequest/index.web.ts index 15ebdca70a44..9b72ee30de57 100644 --- a/src/libs/navigateAfterJoinRequest/index.web.ts +++ b/src/libs/navigateAfterJoinRequest/index.web.ts @@ -4,7 +4,7 @@ import ROUTES from '@src/ROUTES'; const navigateAfterJoinRequest = () => { // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, true); + Navigation.goBack(undefined, {shouldPopToTop: true}); if (getIsSmallScreenWidth()) { Navigation.navigate(ROUTES.SETTINGS); } diff --git a/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx b/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx index 55f19f8c35b9..060d5664ac93 100644 --- a/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx +++ b/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx @@ -52,7 +52,7 @@ function AddBankAccount() { PaymentMethods.continueSetup(onSuccessFallbackRoute); return; } - Navigation.goBack(ROUTES.SETTINGS_WALLET, true); + Navigation.goBack(ROUTES.SETTINGS_WALLET, {shouldPopToTop: true}); }; const handleBackButtonPress = () => { @@ -63,7 +63,7 @@ function AddBankAccount() { if (screenIndex === 0) { BankAccounts.clearPersonalBankAccount(); Wallet.updateCurrentStep(null); - Navigation.goBack(ROUTES.SETTINGS_WALLET, true); + Navigation.goBack(ROUTES.SETTINGS_WALLET, {shouldPopToTop: true}); return; } prevScreen(); diff --git a/src/pages/EnablePayments/EnablePayments.tsx b/src/pages/EnablePayments/EnablePayments.tsx index 357a2be9b1e0..b8aeb4103a59 100644 --- a/src/pages/EnablePayments/EnablePayments.tsx +++ b/src/pages/EnablePayments/EnablePayments.tsx @@ -46,7 +46,7 @@ function EnablePaymentsPage() { > Navigation.goBack(ROUTES.SETTINGS_WALLET, true)} + onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET, {shouldPopToTop: true})} /> diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 6d956d95829e..de66614c82c4 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -295,7 +295,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro return; } // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, true); + Navigation.goBack(undefined, {shouldPopToTop: true}); }, [isInNarrowPaneModal]); let headerView = ( @@ -592,7 +592,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro if (Navigation.getTopmostReportId() === prevOnyxReportID) { Navigation.setShouldPopAllStateOnUP(true); // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, true); + Navigation.goBack(undefined, {shouldPopToTop: true}); } if (prevReport?.parentReportID) { // Prevent navigation to the IOU/Expense Report if it is pending deletion. diff --git a/src/pages/workspace/WorkspaceJoinUserPage.tsx b/src/pages/workspace/WorkspaceJoinUserPage.tsx index 9c79e02d40fc..66caff7263ef 100644 --- a/src/pages/workspace/WorkspaceJoinUserPage.tsx +++ b/src/pages/workspace/WorkspaceJoinUserPage.tsx @@ -47,7 +47,7 @@ function WorkspaceJoinUserPage({route, policy}: WorkspaceJoinUserPageProps) { Navigation.isNavigationReady().then(() => { // @TODO: Check if this method works the same as on the main branch // NOTE: It probably doesn't need any params. When this method is called, shouldPopAllStateOnUP is always false - Navigation.goBack(undefined, true); + Navigation.goBack(undefined, {shouldPopToTop: true}); Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID ?? '-1')); }); return; From 3afe817a754af2df0361833eaa446fa6dea286f2 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 26 Nov 2024 17:07:32 +0100 Subject: [PATCH 12/26] Remove LHN_TO_SPLIT_NAVIGATOR_MAPPING --- .../getInitialSplitNavigatorState.ts | 14 +++--- src/libs/Navigation/Navigation.ts | 4 +- .../LHN_TO_SPLIT_NAVIGATOR_MAPPING.ts | 11 ----- src/libs/Navigation/types.ts | 48 +++++++++---------- 4 files changed, 33 insertions(+), 44 deletions(-) delete mode 100644 src/libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING.ts diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts index de272f67d926..65ca59f9d8db 100644 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts +++ b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts @@ -1,26 +1,26 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; -import LHN_TO_SPLIT_NAVIGATOR_NAME from '@libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING'; -import type {NavigationPartialRoute, SplitNavigatorByLHN, SplitNavigatorParamListType, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; +import SIDEBAR_TO_SPLIT from '@libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_SPLIT'; +import type {NavigationPartialRoute, SplitNavigatorBySidebar, SplitNavigatorParamListType, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; -type ExtractRouteType = Extract; +type ExtractRouteType = Extract; // The function getPathFromState that we are using in some places isn't working correctly without defined index. const getRoutesWithIndex = (routes: NavigationPartialRoute[]): PartialState => ({routes, index: routes.length - 1}); function getInitialSplitNavigatorState( - splitNavigatorLHN: NavigationPartialRoute, + splitNavigatorSidebarRoute: NavigationPartialRoute, route?: NavigationPartialRoute>, splitNavigatorParams?: Record, -): NavigationPartialRoute> { +): NavigationPartialRoute> { const routes = []; - routes.push(splitNavigatorLHN); + routes.push(splitNavigatorSidebarRoute); if (route) { routes.push(route); } return { - name: LHN_TO_SPLIT_NAVIGATOR_NAME[splitNavigatorLHN.name], + name: SIDEBAR_TO_SPLIT[splitNavigatorSidebarRoute.name], state: getRoutesWithIndex(routes), params: splitNavigatorParams, }; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 2f682112ee9d..8f59b828bdd3 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -196,7 +196,7 @@ type GoBackOptions = { shouldPopToTop?: boolean; }; -const defaultGoUpOptions: Required = { +const defaultGoBackOptions: Required = { compareParams: true, shouldPopToTop: false, }; @@ -206,7 +206,7 @@ function isRootNavigatorState(state: State): state is State } function goUp(fallbackRoute: Route, options?: GoBackOptions) { - const compareParams = options?.compareParams ?? defaultGoUpOptions.compareParams; + const compareParams = options?.compareParams ?? defaultGoBackOptions.compareParams; if (!canNavigate('goBack')) { return; diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING.ts b/src/libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING.ts deleted file mode 100644 index 2871d34adaf8..000000000000 --- a/src/libs/Navigation/linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING.ts +++ /dev/null @@ -1,11 +0,0 @@ -// @TODO remove this file before merging to the main. -import NAVIGATORS from '@src/NAVIGATORS'; -import SCREENS from '@src/SCREENS'; - -const LHN_TO_SPLIT_NAVIGATOR_NAME = { - [SCREENS.SETTINGS.ROOT]: NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, - [SCREENS.HOME]: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, - [SCREENS.WORKSPACE.INITIAL]: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, -}; - -export default LHN_TO_SPLIT_NAVIGATOR_NAME; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 9483ae20274e..417663088dbe 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -22,7 +22,7 @@ import type SCREENS from '@src/SCREENS'; import type EXIT_SURVEY_REASON_FORM_INPUT_IDS from '@src/types/form/ExitSurveyReasonForm'; import type {CompanyCardFeed} from '@src/types/onyx'; import type {ConnectionName, SageIntacctMappingName} from '@src/types/onyx/Policy'; -import type LHN_TO_SPLIT_NAVIGATOR_NAME from './linkingConfig/RELATIONS/LHN_TO_SPLIT_NAVIGATOR_MAPPING'; +import type SIDEBAR_TO_SPLIT from './linkingConfig/RELATIONS/SIDEBAR_TO_SPLIT'; type NavigationRef = NavigationContainerRefWithCurrent; @@ -53,7 +53,7 @@ type NavigationPartialRoute = PartialRoute = NavigationState | PartialState>; -type SplitNavigatorSidebarScreen = keyof typeof LHN_TO_SPLIT_NAVIGATOR_NAME; +type SplitNavigatorSidebarScreen = keyof typeof SIDEBAR_TO_SPLIT; type SplitNavigatorParamListType = { [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: SettingsSplitNavigatorParamList; @@ -61,7 +61,7 @@ type SplitNavigatorParamListType = { [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: WorkspaceSplitNavigatorParamList; }; -type SplitNavigatorByLHN = (typeof LHN_TO_SPLIT_NAVIGATOR_NAME)[T]; +type SplitNavigatorBySidebar = (typeof SIDEBAR_TO_SPLIT)[T]; type CentralPaneScreensParamList = { [SCREENS.REPORT]: { @@ -1752,18 +1752,20 @@ declare global { export type { AddPersonalBankAccountNavigatorParamList, AuthScreensParamList, - CentralPaneScreensParamList, - CentralPaneName, - BackToParams, BackToAndForwardToParms, + BackToParams, + CentralPaneName, + CentralPaneScreensParamList, + DebugParamList, DetailsNavigatorParamList, EditRequestNavigatorParamList, EnablePaymentsNavigatorParamList, ExplanationModalNavigatorParamList, + FeatureTrainingNavigatorParamList, FlagCommentNavigatorParamList, - WorkspaceScreenName, - WorkspaceSplitNavigatorParamList, + FullScreenName, LeftModalNavigatorParamList, + MissingPersonalDetailsParamList, MoneyRequestNavigatorParamList, NavigationPartialRoute, NavigationRef, @@ -1771,8 +1773,8 @@ export type { NavigationStateRoute, NewChatNavigatorParamList, NewTaskNavigatorParamList, - OnboardingModalNavigatorParamList, OnboardingFlowName, + OnboardingModalNavigatorParamList, ParticipantsNavigatorParamList, PrivateNotesNavigatorParamList, ProfileNavigatorParamList, @@ -1783,34 +1785,32 @@ export type { ReportDetailsNavigatorParamList, ReportSettingsNavigatorParamList, ReportsSplitNavigatorParamList, + RestrictedActionParamList, RightModalNavigatorParamList, RoomMembersNavigatorParamList, RootStackParamList, + SearchAdvancedFiltersParamList, + SearchReportParamList, + SearchSavedSearchParamList, SettingsNavigatorParamList, SettingsSplitNavigatorParamList, SignInNavigatorParamList, - FeatureTrainingNavigatorParamList, SplitDetailsNavigatorParamList, + SplitNavigatorBySidebar, + SplitNavigatorName, + SplitNavigatorParamListType, + SplitNavigatorScreenName, + SplitNavigatorSidebarScreen, StackNavigationAction, State, StateOrRoute, SwitchPolicyIDParams, - TravelNavigatorParamList, TaskDetailsNavigatorParamList, TeachersUniteNavigatorParamList, + TransactionDuplicateNavigatorParamList, + TravelNavigatorParamList, WalletStatementNavigatorParamList, WelcomeVideoModalNavigatorParamList, - TransactionDuplicateNavigatorParamList, - SearchReportParamList, - SearchAdvancedFiltersParamList, - SearchSavedSearchParamList, - RestrictedActionParamList, - MissingPersonalDetailsParamList, - DebugParamList, - SplitNavigatorName, - SplitNavigatorScreenName, - FullScreenName, - SplitNavigatorSidebarScreen, - SplitNavigatorParamListType, - SplitNavigatorByLHN, + WorkspaceScreenName, + WorkspaceSplitNavigatorParamList, }; From 324b59859e7ff28b07a92b7a47abd013c687ef00 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 27 Nov 2024 08:17:25 +0100 Subject: [PATCH 13/26] Cleanup navigation types and remove redundant mapping files --- .../Navigation/AppNavigator/AuthScreens.tsx | 2 +- .../createResponsiveStackNavigator/index.tsx | 2 +- .../RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts | 46 ------- src/libs/Navigation/types.ts | 127 +++++++----------- 4 files changed, 49 insertions(+), 128 deletions(-) delete mode 100755 src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index f73f424ccacb..4100b58c4173 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -29,7 +29,6 @@ import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOptions/presentation'; import type {AuthScreensParamList} from '@libs/Navigation/types'; -import {isOnboardingFlowName} from '@libs/NavigationUtils'; import NetworkConnection from '@libs/NetworkConnection'; import onyxSubscribe from '@libs/onyxSubscribe'; import * as Pusher from '@libs/Pusher/pusher'; @@ -58,6 +57,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; +import {isOnboardingFlowName} from '../helpers'; import createResponsiveStackNavigator from './createResponsiveStackNavigator'; import defaultScreenOptions from './defaultScreenOptions'; import ExplanationModalNavigator from './Navigators/ExplanationModalNavigator'; diff --git a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/index.tsx index 07920b5ad416..5662b394339c 100644 --- a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/index.tsx @@ -1,10 +1,10 @@ import type {ParamListBase} from '@react-navigation/native'; import {createNavigatorFactory} from '@react-navigation/native'; import useNavigationResetOnLayoutChange from '@libs/Navigation/AppNavigator/useNavigationResetOnLayoutChange'; +import {isFullScreenName} from '@libs/Navigation/helpers'; import createPlatformStackNavigatorComponent from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigatorComponent'; import defaultPlatformStackScreenOptions from '@libs/Navigation/PlatformStackNavigation/defaultPlatformStackScreenOptions'; import type {CustomStateHookProps, PlatformStackNavigationEventMap, PlatformStackNavigationOptions, PlatformStackNavigationState} from '@libs/Navigation/PlatformStackNavigation/types'; -import {isFullScreenName} from '@libs/NavigationUtils'; import CustomRouter from './CustomRouter'; function useCustomRouterState({state}: CustomStateHookProps) { diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts b/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts deleted file mode 100755 index d5c1b6089812..000000000000 --- a/src/libs/Navigation/linkingConfig/RELATIONS/TAB_TO_CENTRAL_PANE_MAPPING.ts +++ /dev/null @@ -1,46 +0,0 @@ -// @TODO Remove this file before merging to the main. -import type {SplitNavigatorScreenName, SplitNavigatorSidebarScreen} from '@navigation/types'; -import SCREENS from '@src/SCREENS'; - -const TAB_TO_CENTRAL_PANE_MAPPING: Record = { - [SCREENS.HOME]: [SCREENS.REPORT], - [SCREENS.SETTINGS.ROOT]: [ - SCREENS.SETTINGS.PROFILE.ROOT, - SCREENS.SETTINGS.PREFERENCES.ROOT, - SCREENS.SETTINGS.SECURITY, - SCREENS.SETTINGS.WALLET.ROOT, - SCREENS.SETTINGS.ABOUT, - SCREENS.SETTINGS.WORKSPACES, - SCREENS.SETTINGS.SAVE_THE_WORLD, - SCREENS.SETTINGS.TROUBLESHOOT, - SCREENS.SETTINGS.SUBSCRIPTION.ROOT, - ], - [SCREENS.WORKSPACE.INITIAL]: [ - SCREENS.WORKSPACE.PROFILE, - SCREENS.WORKSPACE.MEMBERS, - SCREENS.WORKSPACE.WORKFLOWS, - SCREENS.WORKSPACE.ACCOUNTING.ROOT, - SCREENS.WORKSPACE.TAXES, - SCREENS.WORKSPACE.TAGS, - SCREENS.WORKSPACE.CATEGORIES, - SCREENS.WORKSPACE.DISTANCE_RATES, - SCREENS.WORKSPACE.REPORT_FIELDS, - SCREENS.WORKSPACE.INVOICES, - SCREENS.WORKSPACE.EXPENSIFY_CARD, - ], -}; - -const generateCentralPaneToTabMapping = (): Record => { - const mapping: Record = {} as Record; - for (const [tabName, CentralPaneNames] of Object.entries(TAB_TO_CENTRAL_PANE_MAPPING)) { - for (const CentralPaneName of CentralPaneNames) { - mapping[CentralPaneName] = tabName as SplitNavigatorScreenName; - } - } - return mapping; -}; - -const CENTRAL_PANE_TO_TAB_MAPPING: Record = generateCentralPaneToTabMapping(); - -export {CENTRAL_PANE_TO_TAB_MAPPING}; -export default TAB_TO_CENTRAL_PANE_MAPPING; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 417663088dbe..4ddac42dd130 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -63,29 +63,6 @@ type SplitNavigatorParamListType = { type SplitNavigatorBySidebar = (typeof SIDEBAR_TO_SPLIT)[T]; -type CentralPaneScreensParamList = { - [SCREENS.REPORT]: { - reportActionID: string; - reportID: string; - openOnAdminRoom?: boolean; - referrer?: string; - }; - // [SCREENS.SETTINGS.WORKSPACES]: undefined; - [SCREENS.SETTINGS.PREFERENCES.ROOT]: undefined; - // [SCREENS.SETTINGS.PROFILE.ROOT]: undefined; - [SCREENS.SETTINGS.SECURITY]: undefined; - // [SCREENS.SETTINGS.WALLET.ROOT]: undefined; - [SCREENS.SETTINGS.ABOUT]: undefined; - [SCREENS.SETTINGS.TROUBLESHOOT]: undefined; - - [SCREENS.SEARCH.CENTRAL_PANE]: { - q: SearchQueryString; - name?: string; - }; - // [SCREENS.SETTINGS.SAVE_THE_WORLD]: undefined; - [SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: undefined; -}; - type BackToParams = { backTo?: Routes; }; @@ -1600,53 +1577,54 @@ type PublicScreensParamList = SharedScreensParamList & { [SCREENS.CONNECTION_COMPLETE]: undefined; }; -type AuthScreensParamList = CentralPaneScreensParamList & - SharedScreensParamList & { - [SCREENS.CONCIERGE]: undefined; - [SCREENS.TRACK_EXPENSE]: undefined; - [SCREENS.SUBMIT_EXPENSE]: undefined; - [SCREENS.ATTACHMENTS]: { - reportID: string; - source: string; - type: ValueOf; - accountID: string; - isAuthTokenRequired?: string; - fileName?: string; - attachmentLink?: string; - }; - [SCREENS.PROFILE_AVATAR]: { - accountID: string; - }; - [SCREENS.WORKSPACE_AVATAR]: { - policyID: string; - }; - [SCREENS.WORKSPACE_JOIN_USER]: { - policyID: string; - email: string; - }; - [SCREENS.REPORT_AVATAR]: { - reportID: string; - policyID?: string; - }; - [SCREENS.NOT_FOUND]: undefined; - [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: NavigatorScreenParams & {policyID?: string}; - [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: NavigatorScreenParams & {policyID?: string}; - [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: NavigatorScreenParams; - [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; - [NAVIGATORS.RIGHT_MODAL_NAVIGATOR]: NavigatorScreenParams; - [NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR]: NavigatorScreenParams; - [NAVIGATORS.FEATURE_TRANING_MODAL_NAVIGATOR]: NavigatorScreenParams; - [NAVIGATORS.WELCOME_VIDEO_MODAL_NAVIGATOR]: NavigatorScreenParams; - [NAVIGATORS.EXPLANATION_MODAL_NAVIGATOR]: NavigatorScreenParams; - [SCREENS.DESKTOP_SIGN_IN_REDIRECT]: undefined; - [SCREENS.TRANSACTION_RECEIPT]: { - reportID: string; - transactionID: string; - readonly?: string; - isFromReviewDuplicates?: string; - }; - [SCREENS.CONNECTION_COMPLETE]: undefined; +type AuthScreensParamList = SharedScreensParamList & { + [SCREENS.CONCIERGE]: undefined; + [SCREENS.TRACK_EXPENSE]: undefined; + [SCREENS.SUBMIT_EXPENSE]: undefined; + [SCREENS.ATTACHMENTS]: { + reportID: string; + source: string; + type: ValueOf; + accountID: string; + isAuthTokenRequired?: string; }; + [SCREENS.PROFILE_AVATAR]: { + accountID: string; + }; + [SCREENS.WORKSPACE_AVATAR]: { + policyID: string; + }; + [SCREENS.WORKSPACE_JOIN_USER]: { + policyID: string; + email: string; + }; + [SCREENS.REPORT_AVATAR]: { + reportID: string; + policyID?: string; + }; + [SCREENS.NOT_FOUND]: undefined; + [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: NavigatorScreenParams & {policyID?: string}; + [NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]: NavigatorScreenParams & {policyID?: string}; + [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: NavigatorScreenParams; + [NAVIGATORS.LEFT_MODAL_NAVIGATOR]: NavigatorScreenParams; + [NAVIGATORS.RIGHT_MODAL_NAVIGATOR]: NavigatorScreenParams; + [NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR]: NavigatorScreenParams; + [NAVIGATORS.FEATURE_TRANING_MODAL_NAVIGATOR]: NavigatorScreenParams; + [NAVIGATORS.WELCOME_VIDEO_MODAL_NAVIGATOR]: NavigatorScreenParams; + [NAVIGATORS.EXPLANATION_MODAL_NAVIGATOR]: NavigatorScreenParams; + [SCREENS.DESKTOP_SIGN_IN_REDIRECT]: undefined; + [SCREENS.TRANSACTION_RECEIPT]: { + reportID: string; + transactionID: string; + readonly?: string; + isFromReviewDuplicates?: string; + }; + [SCREENS.CONNECTION_COMPLETE]: undefined; + [SCREENS.SEARCH.CENTRAL_PANE]: { + q: SearchQueryString; + name?: string; + }; +}; type SearchReportParamList = { [SCREENS.SEARCH.REPORT_RHP]: { @@ -1725,8 +1703,6 @@ type RootStackParamList = PublicScreensParamList & AuthScreensParamList & LeftMo type WorkspaceScreenName = keyof WorkspaceSplitNavigatorParamList; -type CentralPaneName = keyof CentralPaneScreensParamList; - type OnboardingFlowName = keyof OnboardingModalNavigatorParamList; type SplitNavigatorName = keyof SplitNavigatorParamListType; @@ -1735,12 +1711,6 @@ type SplitNavigatorScreenName = keyof (WorkspaceSplitNavigatorParamList & Settin type FullScreenName = SplitNavigatorName | typeof SCREENS.SEARCH.CENTRAL_PANE; -type SwitchPolicyIDParams = { - policyID?: string; - route?: Routes; - isPolicyAdmin?: boolean; -}; - declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace ReactNavigation { @@ -1754,8 +1724,6 @@ export type { AuthScreensParamList, BackToAndForwardToParms, BackToParams, - CentralPaneName, - CentralPaneScreensParamList, DebugParamList, DetailsNavigatorParamList, EditRequestNavigatorParamList, @@ -1804,7 +1772,6 @@ export type { StackNavigationAction, State, StateOrRoute, - SwitchPolicyIDParams, TaskDetailsNavigatorParamList, TeachersUniteNavigatorParamList, TransactionDuplicateNavigatorParamList, From f44db08bf4030705984085387f5b3228655bb7c8 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 27 Nov 2024 15:57:20 +0100 Subject: [PATCH 14/26] Add missing docs to navigation functions --- src/libs/Navigation/Navigation.ts | 88 +++++++++++-------- .../helpers/customGetPathFromState.ts | 1 + .../helpers/getOnboardingAdaptedState.ts | 4 + .../helpers/getPolicyIDFromState.ts | 2 +- .../helpers/getTopmostReportParam.ts | 3 +- .../Navigation/helpers/isNavigatorName.ts | 4 + .../Navigation/helpers/isReportOpenInRHP.ts | 1 + .../index.android.ts | 2 +- 8 files changed, 67 insertions(+), 38 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 8f59b828bdd3..1342fb620e17 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -36,6 +36,7 @@ import RELATIONS from './linkingConfig/RELATIONS'; import navigationRef from './navigationRef'; import type {NavigationPartialRoute, NavigationStateRoute, RootStackParamList, State} from './types'; +// Get the sidebar screen parameters from the split navigator passed as a param function getSidebarScreenParams(splitNavigatorRoute: NavigationStateRoute) { if (splitNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { return splitNavigatorRoute.state?.routes?.at(0)?.params; @@ -68,18 +69,16 @@ function canNavigate(methodName: string, params: Record = {}): return false; } -// Re-exporting the getTopmostReportId here to fill in default value for state. The getTopmostReportId isn't defined in this file to avoid cyclic dependencies. +// Extracts from the topmost report its id. const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParam(state, 'reportID'); -// Re-exporting the getTopmostReportActionID here to fill in default value for state. The getTopmostReportActionID isn't defined in this file to avoid cyclic dependencies. +// Extracts from the topmost report its action id. const getTopmostReportActionId = (state = navigationRef.getState()) => getTopmostReportParam(state, 'reportActionID'); // Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies. const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref); -/** - * Function that generates dynamic urls from paths passed from OldDot - */ +// Function that generates dynamic urls from paths passed from OldDot. function parseHybridAppUrl(url: HybridAppRoute | Route): Route { switch (url) { case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL: @@ -94,7 +93,7 @@ function parseHybridAppUrl(url: HybridAppRoute | Route): Route { } } -/** Returns the current active route */ +// Returns the current active route. function getActiveRoute(): string { const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute(); if (!currentRoute?.name) { @@ -109,7 +108,7 @@ function getActiveRoute(): string { return ''; } - +// Returns the route of a report opened in RHP. function getReportRHPActiveRoute(): string { if (isReportOpenInRHP(navigationRef.getRootState())) { return getActiveRoute(); @@ -146,10 +145,14 @@ function navigate(route: Route = ROUTES.HOME, type?: string) { pendingRoute = route; return; } - // linkTo(navigationRef.current, route, type, isActiveRoute(route)); + linkTo(navigationRef.current, route, type); } +/** + * When routes are compared to determine whether the fallback route passed to the goUp function is in the state, + * these parameters shouldn't be included in the comparison. + */ const routeParamsIgnore = ['path', 'initial', 'params', 'state', 'screen', 'policyID']; // If we use destructuring, we will get an error if any of the ignored properties are not present in the object. @@ -186,13 +189,24 @@ function doesRouteMatchToMinimalActionPayload(route: NavigationStateRoute | Navi return shallowCompare(routeParams, minimalActionParams); } +// Checks whether the given state is the root navigator state +function isRootNavigatorState(state: State): state is State { + return state.key === navigationRef.current?.getRootState().key; +} + type GoBackOptions = { - /** If we should compare params when searching for a route in state to go up to. + /** + * If we should compare params when searching for a route in state to go up to. * There are situations where we want to compare params when going up e.g. goUp to a specific report. * Sometimes we want to go up and update params of screen e.g. country picker. - * In that case we want to goUp to a country picker with any params so we don't compare them. */ + * In that case we want to goUp to a country picker with any params so we don't compare them. + */ compareParams?: boolean; + /** + * Specifies whether goBack should pop to top when invoked. + * Additionaly, to execute popToTop, set the value of the global variable ShouldPopAllStateOnUP to true using the setShouldPopAllStateOnUP function. + */ shouldPopToTop?: boolean; }; @@ -201,14 +215,17 @@ const defaultGoBackOptions: Required = { shouldPopToTop: false, }; -function isRootNavigatorState(state: State): state is State { - return state.key === navigationRef.current?.getRootState().key; -} - +/** + * Navigate to the given fallbackRoute taking into account whether it is possible to go back to this screen. Within one nested navigator, we can go back by any number + * of screens, but if as a result of going back we would have to remove more than one screen from the rootState, + * replace is performed so as not to lose the visited pages. + * If fallbackRoute is not found in the state, replace is also called then. + * + * @param fallbackRoute - The route to go up. + * @param options - Optional configuration that affects navigation logic, such as parameter comparison. + */ function goUp(fallbackRoute: Route, options?: GoBackOptions) { - const compareParams = options?.compareParams ?? defaultGoBackOptions.compareParams; - - if (!canNavigate('goBack')) { + if (!canNavigate('goUp')) { return; } @@ -231,6 +248,7 @@ function goUp(fallbackRoute: Route, options?: GoBackOptions) { return; } + const compareParams = options?.compareParams ?? defaultGoBackOptions.compareParams; const indexOfFallbackRoute = targetState.routes.findLastIndex((route) => doesRouteMatchToMinimalActionPayload(route, minimalAction, compareParams)); const distanceToPop = targetState.routes.length - indexOfFallbackRoute - 1; @@ -242,8 +260,10 @@ function goUp(fallbackRoute: Route, options?: GoBackOptions) { return; } - // If we are not comparing params, we want to use navigate action because it will replace params in the route already existing in the state if necessary. - // This part will need refactor after migrating to react-navigation 7. We will use popTo instead. + /** + * If we are not comparing params, we want to use navigate action because it will replace params in the route already existing in the state if necessary. + * This part will need refactor after migrating to react-navigation 7. We will use popTo instead. + */ if (!compareParams) { navigationRef.current.dispatch(minimalAction); return; @@ -254,16 +274,14 @@ function goUp(fallbackRoute: Route, options?: GoBackOptions) { /** * @param fallbackRoute - Fallback route if pop/goBack action should, but is not possible within RHP - * @param shouldPopToTop - Should we navigate to LHN on back press + * @param options - Optional configuration that affects navigation logic, e.g. whether goBack should popToTop. */ function goBack(fallbackRoute?: Route, options?: GoBackOptions) { if (!canNavigate('goBack')) { return; } - const shouldPopToTop = options?.shouldPopToTop ?? false; - - if (shouldPopToTop) { + if (options?.shouldPopToTop) { if (shouldPopAllStateOnUP) { shouldPopAllStateOnUP = false; navigationRef.current?.dispatch(StackActions.popToTop()); @@ -302,9 +320,7 @@ function goBack(fallbackRoute?: Route, options?: GoBackOptions) { navigationRef.current?.goBack(); } -/** - * Reset the navigation state to Home page - */ +// Reset the navigation state to Home page function resetToHome() { const isNarrowLayout = getIsNarrowLayout(); const rootState = navigationRef.getRootState(); @@ -318,9 +334,7 @@ function resetToHome() { navigationRef.dispatch({payload, type: 'REPLACE', target: rootState.key}); } -/** - * Update route params for the specified route. - */ +// Update route params for the specified route. function setParams(params: Record, routeKey = '') { navigationRef.current?.dispatch({ ...CommonActions.setParams(params), @@ -328,14 +342,12 @@ function setParams(params: Record, routeKey = '') { }); } -/** - * Returns the current active route without the URL params - */ +// Returns the current active route without the URL params. function getActiveRouteWithoutParams(): string { return getActiveRoute().replace(/\?.*/, ''); } -/** Returns the active route name from a state event from the navigationRef */ +// Returns the active route name from a state event from the navigationRef. function getRouteNameFromStateEvent(event: EventArg<'state', false, NavigationContainerEventMap['state']['data']>): string | undefined { if (!event.data.state) { return; @@ -415,12 +427,17 @@ function waitForProtectedRoutes() { }); } +// Changes the currently selected policy in the app. function switchPolicyID(policyID?: string) { navigationRef.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID, payload: {policyID}}); } type NavigateToReportWithPolicyCheckPayload = {report?: OnyxEntry; reportID?: string; reportActionID?: string; referrer?: string; policyIDToCheck?: string}; +/** + * Navigates to a report passed as a param (as an id or report object) and checks whether the target object belongs to the currently selected workspace. + * If not, the current workspace is set to global. + */ function navigateToReportWithPolicyCheck({report, reportID, reportActionID, referrer, policyIDToCheck}: NavigateToReportWithPolicyCheckPayload, ref = navigationRef) { const targetReport = reportID ? {reportID, ...ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]} : report; const policyID = policyIDToCheck ?? getPolicyIDFromState(navigationRef.getRootState() as State); @@ -453,8 +470,7 @@ function navigateToReportWithPolicyCheck({report, reportID, reportActionID, refe ); } -// @TODO In places where we use dismissModal with report arg we should do dismiss modal and then navigate to the report. -// We left it here to limit the number of changed files. +// Closes the modal navigator (RHP, LHP, onboarding). const dismissModal = (reportID?: string, ref = navigationRef) => { ref.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL}); if (!reportID) { @@ -462,6 +478,8 @@ const dismissModal = (reportID?: string, ref = navigationRef) => { } isNavigationReady().then(() => navigateToReportWithPolicyCheck({reportID})); }; + +// Dismisses the modal and opens the given report. const dismissModalWithReport = (report: OnyxEntry) => { dismissModal(); isNavigationReady().then(() => navigateToReportWithPolicyCheck({report})); diff --git a/src/libs/Navigation/helpers/customGetPathFromState.ts b/src/libs/Navigation/helpers/customGetPathFromState.ts index 0a42aa67a1ce..24fa3dbe1321 100644 --- a/src/libs/Navigation/helpers/customGetPathFromState.ts +++ b/src/libs/Navigation/helpers/customGetPathFromState.ts @@ -2,6 +2,7 @@ import {getPathFromState} from '@react-navigation/native'; import NAVIGATORS from '@src/NAVIGATORS'; import {isFullScreenName} from './isNavigatorName'; +// This function adds the policyID param to the url. const customGetPathFromState: typeof getPathFromState = (state, options) => { const path = getPathFromState(state, options); const fullScreenRoute = state.routes.findLast((route) => isFullScreenName(route.name)); diff --git a/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts b/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts index eee3f9f5e52d..cbb0ac71b8c4 100644 --- a/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts +++ b/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts @@ -1,6 +1,10 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; import SCREENS from '@src/SCREENS'; +/** + * When we open the application via deeplink to a specific onboarding screen, we want the previous onboarding screens to be able to go back to them. + * Therefore, the paths of the previous screens are added here. + */ export default function getOnboardingAdaptedState(state: PartialState): PartialState { const onboardingRoute = state.routes.at(0); if (!onboardingRoute || onboardingRoute.name === SCREENS.ONBOARDING.PURPOSE) { diff --git a/src/libs/Navigation/helpers/getPolicyIDFromState.ts b/src/libs/Navigation/helpers/getPolicyIDFromState.ts index b4b81ee15db8..808455834247 100644 --- a/src/libs/Navigation/helpers/getPolicyIDFromState.ts +++ b/src/libs/Navigation/helpers/getPolicyIDFromState.ts @@ -7,7 +7,7 @@ import extractPolicyIDFromQuery from './extractPolicyIDFromQuery'; * returns policyID value if one exists in navigation state * * PolicyID in this app can be stored in two ways: - * - on most screens but NOT Search as `policyID` param (on bottom tab screens) + * - on NAVIGATORS.REPORTS_SPLIT_NAVIGATOR as `policyID` param * - on Search related screens as policyID filter inside `q` (SearchQuery) param (only for SEARCH_CENTRAL_PANE) */ const getPolicyIDFromState = (state: State): string | undefined => { diff --git a/src/libs/Navigation/helpers/getTopmostReportParam.ts b/src/libs/Navigation/helpers/getTopmostReportParam.ts index 026cd379aa1a..40955d719755 100644 --- a/src/libs/Navigation/helpers/getTopmostReportParam.ts +++ b/src/libs/Navigation/helpers/getTopmostReportParam.ts @@ -6,9 +6,10 @@ import SCREENS from '@src/SCREENS'; // This function is in a separate file than Navigation.ts to avoid cyclic dependency. /** - * Find the last visited report screen in the navigation state and get the id of it. + * Find the last visited report screen in the navigation state and get its specific param (id or action id). * * @param state - The react-navigation state + * @param reportParam - param to get from the report route params * @returns - It's possible that there is no report screen */ diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index ae5118b9833e..db8b103309ec 100644 --- a/src/libs/Navigation/helpers/isNavigatorName.ts +++ b/src/libs/Navigation/helpers/isNavigatorName.ts @@ -18,6 +18,10 @@ const FULL_SCREENS_SET = new Set(FULL_SCREENS); const SIDEBARS_SET = new Set(SIDEBARS); const ONBOARDING_SCREENS_SET = new Set(ONBOARDING_SCREENS); +/** + * Functions defined below are used to check whether a screen belongs to a specific group. + * It is mainly used to filter routes in the navigation state. + */ function checkIfScreenHasMatchingNameToSetValues(screen: string | undefined, set: Set): screen is T { if (!screen) { return false; diff --git a/src/libs/Navigation/helpers/isReportOpenInRHP.ts b/src/libs/Navigation/helpers/isReportOpenInRHP.ts index 51e8a95bb66b..6158c3ec9d04 100644 --- a/src/libs/Navigation/helpers/isReportOpenInRHP.ts +++ b/src/libs/Navigation/helpers/isReportOpenInRHP.ts @@ -2,6 +2,7 @@ import type {NavigationState} from '@react-navigation/native'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; +// Determines whether the report page is opened in RHP. const isReportOpenInRHP = (state: NavigationState | undefined): boolean => { const lastRoute = state?.routes?.at(-1); if (!lastRoute) { diff --git a/src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.android.ts b/src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.android.ts index 04c1791145ca..54b16e09947e 100644 --- a/src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.android.ts +++ b/src/libs/Navigation/helpers/setupCustomAndroidBackHandler/index.android.ts @@ -1,7 +1,7 @@ import {BackHandler, NativeModules} from 'react-native'; import navigationRef from '@navigation/navigationRef'; -// We need to do some custom handling for the back button on Android for actions related to the search page. +// We need to do some custom handling for the back button on Android for actions related to the hybrid app. function setupCustomAndroidBackHandler() { const onBackPress = () => { const rootState = navigationRef.getRootState(); From 216c8128a70b3cd663df1cd9213ebbf2450c3491 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 28 Nov 2024 10:48:48 +0100 Subject: [PATCH 15/26] Cleanup isNavigatorName --- src/libs/Navigation/helpers/isNavigatorName.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/Navigation/helpers/isNavigatorName.ts b/src/libs/Navigation/helpers/isNavigatorName.ts index db8b103309ec..b642526716c0 100644 --- a/src/libs/Navigation/helpers/isNavigatorName.ts +++ b/src/libs/Navigation/helpers/isNavigatorName.ts @@ -1,10 +1,7 @@ +import RELATIONS from '@libs/Navigation/linkingConfig/RELATIONS'; import type {FullScreenName, OnboardingFlowName, SplitNavigatorName, SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; -import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; -const SPLIT_NAVIGATORS = [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]; -const FULL_SCREENS = [...SPLIT_NAVIGATORS, SCREENS.SEARCH.CENTRAL_PANE]; -const SIDEBARS = [SCREENS.HOME, SCREENS.SETTINGS.ROOT, SCREENS.WORKSPACE.INITIAL]; const ONBOARDING_SCREENS = [ SCREENS.ONBOARDING.PERSONAL_DETAILS, SCREENS.ONBOARDING.PURPOSE, @@ -13,9 +10,9 @@ const ONBOARDING_SCREENS = [ SCREENS.ONBOARDING.ACCOUNTING, ]; -const SPLIT_NAVIGATORS_SET = new Set(SPLIT_NAVIGATORS); -const FULL_SCREENS_SET = new Set(FULL_SCREENS); -const SIDEBARS_SET = new Set(SIDEBARS); +const SPLIT_NAVIGATORS_SET = new Set(Object.values(RELATIONS.SIDEBAR_TO_SPLIT)); +const FULL_SCREENS_SET = new Set([...Object.values(RELATIONS.SIDEBAR_TO_SPLIT), SCREENS.SEARCH.CENTRAL_PANE]); +const SIDEBARS_SET = new Set(Object.values(RELATIONS.SPLIT_TO_SIDEBAR)); const ONBOARDING_SCREENS_SET = new Set(ONBOARDING_SCREENS); /** From f46818a310e32af19596156633c0b65496dddf25 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 29 Nov 2024 08:48:34 +0100 Subject: [PATCH 16/26] Adjust comment in SIDEBAR_TO_RHP --- .../Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts index 1923b50b4ea2..4deffa6fd876 100644 --- a/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts @@ -1,8 +1,10 @@ import type {SplitNavigatorSidebarScreen} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; -// This file is used to define the relationship between the sidebar and the right hand pane (RHP) screen. -// These screens don't care about the split navigator's central screen and are in relation directly to the sidebar. +/** + * This file is used to define the relationship between the sidebar and the right hand pane (RHP) screen. + * This means that going back from RHP will take the user directly to the sidebar. On wide layout the default central screen will be used to fill the space. + */ const SIDEBAR_TO_RHP: Partial> = { [SCREENS.SETTINGS.ROOT]: [ SCREENS.SETTINGS.SHARE_CODE, From 7cf08be593397e20831b4fc2146cac26fdb06a6d Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 29 Nov 2024 09:56:02 +0100 Subject: [PATCH 17/26] Refactor getTopmostReportParam to getTopmostReportParams --- src/libs/Navigation/Navigation.ts | 6 +++--- ...ostReportParam.ts => getTopmostReportParams.ts} | 14 +++++--------- src/libs/Navigation/helpers/index.ts | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) rename src/libs/Navigation/helpers/{getTopmostReportParam.ts => getTopmostReportParams.ts} (65%) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 1342fb620e17..865294ae0832 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -24,7 +24,7 @@ import { getMinimalAction, getPolicyIDFromState, getStateFromPath, - getTopmostReportParam, + getTopmostReportParams, isReportOpenInRHP, isSplitNavigatorName, linkTo, @@ -70,10 +70,10 @@ function canNavigate(methodName: string, params: Record = {}): } // Extracts from the topmost report its id. -const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParam(state, 'reportID'); +const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID; // Extracts from the topmost report its action id. -const getTopmostReportActionId = (state = navigationRef.getState()) => getTopmostReportParam(state, 'reportActionID'); +const getTopmostReportActionId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportActionID; // Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies. const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref); diff --git a/src/libs/Navigation/helpers/getTopmostReportParam.ts b/src/libs/Navigation/helpers/getTopmostReportParams.ts similarity index 65% rename from src/libs/Navigation/helpers/getTopmostReportParam.ts rename to src/libs/Navigation/helpers/getTopmostReportParams.ts index 40955d719755..618b8760add4 100644 --- a/src/libs/Navigation/helpers/getTopmostReportParam.ts +++ b/src/libs/Navigation/helpers/getTopmostReportParams.ts @@ -1,22 +1,20 @@ import type {NavigationState, PartialState} from '@react-navigation/native'; -import type {RootStackParamList} from '@libs/Navigation/types'; +import type {ReportsSplitNavigatorParamList, RootStackParamList} from '@libs/Navigation/types'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; // This function is in a separate file than Navigation.ts to avoid cyclic dependency. /** - * Find the last visited report screen in the navigation state and get its specific param (id or action id). + * Find the last visited report screen in the navigation state and get its params. * * @param state - The react-navigation state - * @param reportParam - param to get from the report route params * @returns - It's possible that there is no report screen */ type State = NavigationState | NavigationState | PartialState; -type ReportParam = 'reportID' | 'reportActionID'; -function getTopmostReportParam(state: State, reportParam: ReportParam): string | undefined { +function getTopmostReportParams(state: State): ReportsSplitNavigatorParamList[typeof SCREENS.REPORT] | undefined { if (!state) { return; } @@ -33,9 +31,7 @@ function getTopmostReportParam(state: State, reportParam: ReportParam): string | return; } - const topmostReportParams = topmostReport?.params as Record; - - return topmostReportParams?.[reportParam]; + return topmostReport?.params as ReportsSplitNavigatorParamList[typeof SCREENS.REPORT]; } -export default getTopmostReportParam; +export default getTopmostReportParams; diff --git a/src/libs/Navigation/helpers/index.ts b/src/libs/Navigation/helpers/index.ts index d3756c09b877..71ef89bedf7e 100644 --- a/src/libs/Navigation/helpers/index.ts +++ b/src/libs/Navigation/helpers/index.ts @@ -10,7 +10,7 @@ export {default as getOnboardingAdaptedState} from './getOnboardingAdaptedState' export {default as getParamsFromRoute} from './getParamsFromRoute'; export {default as getPolicyIDFromState} from './getPolicyIDFromState'; export {default as getStateFromPath} from './getStateFromPath'; -export {default as getTopmostReportParam} from './getTopmostReportParam'; +export {default as getTopmostReportParams} from './getTopmostReportParams'; export {default as getTopmostRouteName} from './getTopmostRouteName'; export {default as isReportOpenInRHP} from './isReportOpenInRHP'; export {default as isSearchTopmostFullScreenRoute} from './isSearchTopmostFullScreenRoute'; From 21f7bf6c199ff93370d8a8f9baa950f084fa7abc Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 29 Nov 2024 10:05:01 +0100 Subject: [PATCH 18/26] Adjust getOnboardingAdaptedState docs --- src/libs/Navigation/helpers/getOnboardingAdaptedState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts b/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts index cbb0ac71b8c4..97f02bd91509 100644 --- a/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts +++ b/src/libs/Navigation/helpers/getOnboardingAdaptedState.ts @@ -3,7 +3,7 @@ import SCREENS from '@src/SCREENS'; /** * When we open the application via deeplink to a specific onboarding screen, we want the previous onboarding screens to be able to go back to them. - * Therefore, the paths of the previous screens are added here. + * Therefore, the routes of the previous screens are added here. */ export default function getOnboardingAdaptedState(state: PartialState): PartialState { const onboardingRoute = state.routes.at(0); From b11cba2f6d97414ec2fe34dc273ef9f2916752da Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 10:18:40 +0100 Subject: [PATCH 19/26] Adjust screen navigation props types --- src/components/ScreenWrapper.tsx | 4 ++-- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 2 +- .../createResponsiveStackNavigator/CustomRouter.ts | 2 +- src/libs/Navigation/types.ts | 2 ++ src/pages/home/ReportScreen.tsx | 4 ++-- src/pages/home/report/ReportActionsList.tsx | 8 ++++---- src/pages/home/report/ReportActionsView.tsx | 4 ++-- src/pages/home/report/UserTypingEventListener.tsx | 4 ++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index c8d1aa474eb9..59bd36a8ddc5 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -16,7 +16,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as Browser from '@libs/Browser'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; -import type {AuthScreensParamList, RootStackParamList} from '@libs/Navigation/types'; +import type {ReportsSplitNavigatorParamList, RootStackParamList} from '@libs/Navigation/types'; import toggleTestToolsModal from '@userActions/TestTool'; import CONST from '@src/CONST'; import CustomDevMenu from './CustomDevMenu'; @@ -99,7 +99,7 @@ type ScreenWrapperProps = { * * This is required because transitionEnd event doesn't trigger in the testing environment. */ - navigation?: PlatformStackNavigationProp | PlatformStackNavigationProp; + navigation?: PlatformStackNavigationProp | PlatformStackNavigationProp; /** Whether to show offline indicator on wide screens */ shouldShowOfflineIndicatorInWideScreen?: boolean; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 4100b58c4173..0743e1798f79 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -24,6 +24,7 @@ import KeyboardShortcut from '@libs/KeyboardShortcut'; import Log from '@libs/Log'; import NavBarManager from '@libs/NavBarManager'; import getCurrentUrl from '@libs/Navigation/currentUrl'; +import {isOnboardingFlowName} from '@libs/Navigation/helpers'; import SIDEBAR_TO_SPLIT from '@libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_SPLIT'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; @@ -57,7 +58,6 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; -import {isOnboardingFlowName} from '../helpers'; import createResponsiveStackNavigator from './createResponsiveStackNavigator'; import defaultScreenOptions from './defaultScreenOptions'; import ExplanationModalNavigator from './Navigators/ExplanationModalNavigator'; diff --git a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts index 94bb91fb5434..15aa6b0e9d14 100644 --- a/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createResponsiveStackNavigator/CustomRouter.ts @@ -68,7 +68,7 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { } if (isDismissModalAction(action)) { - return GetStateForActionHandlers.handleDismissModalAction(state, action, configOptions, stackRouter); + return GetStateForActionHandlers.handleDismissModalAction(state, configOptions, stackRouter); } if (isPushAction(action)) { diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 4ddac42dd130..07ba941555e8 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1587,6 +1587,8 @@ type AuthScreensParamList = SharedScreensParamList & { type: ValueOf; accountID: string; isAuthTokenRequired?: string; + fileName?: string; + attachmentLink?: string; }; [SCREENS.PROFILE_AVATAR]: { accountID: string; diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index de66614c82c4..0f80147cbfa4 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -39,7 +39,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import shouldFetchReport from '@libs/shouldFetchReport'; import * as ValidationUtils from '@libs/ValidationUtils'; -import type {AuthScreensParamList} from '@navigation/types'; +import type {ReportsSplitNavigatorParamList} from '@navigation/types'; import * as ComposerActions from '@userActions/Composer'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; @@ -56,7 +56,7 @@ import ReportFooter from './report/ReportFooter'; import type {ActionListContextType, ReactionListRef, ScrollPosition} from './ReportScreenContext'; import {ActionListContext, ReactionListContext} from './ReportScreenContext'; -type ReportScreenNavigationProps = PlatformStackScreenProps; +type ReportScreenNavigationProps = PlatformStackScreenProps; type ReportScreenProps = CurrentReportIDContextValue & ReportScreenNavigationProps; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index ec14c55b36a6..9fa5c1e3f3f3 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -3,10 +3,10 @@ import {useIsFocused, useRoute} from '@react-navigation/native'; // eslint-disable-next-line lodash/import-scope import type {DebouncedFunc} from 'lodash'; import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'; -import {DeviceEventEmitter, InteractionManager, View} from 'react-native'; import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; +import {DeviceEventEmitter, InteractionManager, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import InvertedFlatList from '@components/InvertedFlatList'; import {AUTOSCROLL_TO_TOP_THRESHOLD} from '@components/InvertedFlatList/BaseInvertedFlatList'; import {usePersonalDetails} from '@components/OnyxProvider'; @@ -26,7 +26,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportConnection from '@libs/ReportConnection'; import * as ReportUtils from '@libs/ReportUtils'; import Visibility from '@libs/Visibility'; -import type {AuthScreensParamList} from '@navigation/types'; +import type {ReportsSplitNavigatorParamList} from '@navigation/types'; import variables from '@styles/variables'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; @@ -158,7 +158,7 @@ function ReportActionsList({ const {preferredLocale} = useLocalize(); const {isOffline, lastOfflineAt, lastOnlineAt} = useNetworkWithOfflineStatus(); - const route = useRoute>(); + const route = useRoute>(); const reportScrollManager = useReportScrollManager(); const userActiveSince = useRef(DateUtils.getDBTime()); const lastMessageTime = useRef(null); diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index ee7c929acc7d..95a8bc677ad7 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -11,7 +11,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import DateUtils from '@libs/DateUtils'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; -import type {AuthScreensParamList} from '@libs/Navigation/types'; +import type {ReportsSplitNavigatorParamList} from '@libs/Navigation/types'; import * as NumberUtils from '@libs/NumberUtils'; import {generateNewRandomInt} from '@libs/NumberUtils'; import Performance from '@libs/Performance'; @@ -86,7 +86,7 @@ function ReportActionsView({ }: ReportActionsViewProps) { useCopySelectionHelper(); const reactionListRef = useContext(ReactionListContext); - const route = useRoute>(); + const route = useRoute>(); const [session] = useOnyx(ONYXKEYS.SESSION); const [transactionThreadReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID ?? -1}`, { selector: (reportActions: OnyxEntry) => diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx index 73062902f63e..6609e48161b2 100644 --- a/src/pages/home/report/UserTypingEventListener.tsx +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -4,7 +4,7 @@ import {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; -import type {AuthScreensParamList} from '@libs/Navigation/types'; +import type {ReportsSplitNavigatorParamList} from '@libs/Navigation/types'; import * as Report from '@userActions/Report'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -19,7 +19,7 @@ function UserTypingEventListener({report}: UserTypingEventListenerProps) { const didSubscribeToReportTypingEvents = useRef(false); const reportID = report.reportID; const isFocused = useIsFocused(); - const route = useRoute>(); + const route = useRoute>(); useEffect( () => () => { From b15bccae514e61013d8e8070cde3e05dfcce0fdf Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 10:40:20 +0100 Subject: [PATCH 20/26] Rename SplitStack to Split --- .../Navigators/ReportsSplitNavigator.tsx | 12 ++++++------ .../Navigators/SettingsSplitNavigator.tsx | 12 ++++++------ .../Navigators/WorkspaceSplitNavigator.tsx | 12 ++++++------ .../SplitRouter.ts} | 10 +++++----- .../getInitialSplitNavigatorState.ts | 0 .../index.tsx | 4 ++-- .../AppNavigator/createSplitNavigator/types.ts | 11 +++++++++++ .../useHandleScreenResize/index.native.ts | 0 .../useHandleScreenResize/index.ts | 0 .../usePrepareSplitStackNavigatorChildren.ts | 2 +- .../usePreserveSplitNavigatorState.ts | 0 .../createSplitStackNavigator/types.ts | 16 ---------------- src/libs/Navigation/Navigation.ts | 2 +- src/libs/Navigation/NavigationRoot.tsx | 2 +- .../helpers/getAdaptedStateFromPath.ts | 2 +- src/pages/home/sidebar/BottomTabAvatar.tsx | 2 +- 16 files changed, 41 insertions(+), 46 deletions(-) rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator/SplitStackRouter.ts => createSplitNavigator/SplitRouter.ts} (95%) rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator => createSplitNavigator}/getInitialSplitNavigatorState.ts (100%) rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator => createSplitNavigator}/index.tsx (96%) create mode 100644 src/libs/Navigation/AppNavigator/createSplitNavigator/types.ts rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator => createSplitNavigator}/useHandleScreenResize/index.native.ts (100%) rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator => createSplitNavigator}/useHandleScreenResize/index.ts (100%) rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator => createSplitNavigator}/usePrepareSplitStackNavigatorChildren.ts (88%) rename src/libs/Navigation/AppNavigator/{createSplitStackNavigator => createSplitNavigator}/usePreserveSplitNavigatorState.ts (100%) delete mode 100644 src/libs/Navigation/AppNavigator/createSplitStackNavigator/types.ts diff --git a/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx index 73972199e7b7..277e1cda3398 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx @@ -3,7 +3,7 @@ import React, {useRef} from 'react'; import FocusTrapForScreens from '@components/FocusTrap/FocusTrapForScreen'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; import usePermissions from '@hooks/usePermissions'; -import createSplitStackNavigator from '@libs/Navigation/AppNavigator/createSplitStackNavigator'; +import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import FreezeWrapper from '@libs/Navigation/AppNavigator/FreezeWrapper'; import useRootNavigatorOptions from '@libs/Navigation/AppNavigator/useRootNavigatorOptions'; import getCurrentUrl from '@libs/Navigation/currentUrl'; @@ -17,7 +17,7 @@ import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; const loadReportScreen = () => require('../../../../pages/home/ReportScreen').default; const loadSidebarScreen = () => require('@pages/home/sidebar/SidebarScreen').default; -const Stack = createSplitStackNavigator(); +const Split = createSplitNavigator(); function ReportsSplitNavigator() { const {canUseDefaultRooms} = usePermissions(); @@ -47,23 +47,23 @@ function ReportsSplitNavigator() { return ( - - - - + ); diff --git a/src/libs/Navigation/AppNavigator/Navigators/SettingsSplitNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/SettingsSplitNavigator.tsx index ca2aab050274..e55285986773 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/SettingsSplitNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/SettingsSplitNavigator.tsx @@ -1,7 +1,7 @@ import {useRoute} from '@react-navigation/native'; import React from 'react'; import FocusTrapForScreens from '@components/FocusTrap/FocusTrapForScreen'; -import createSplitStackNavigator from '@libs/Navigation/AppNavigator/createSplitStackNavigator'; +import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import useRootNavigatorOptions from '@libs/Navigation/AppNavigator/useRootNavigatorOptions'; import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; @@ -25,7 +25,7 @@ const CENTRAL_PANE_SETTINGS_SCREENS = { [SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: () => require('../../../../pages/settings/Subscription/SubscriptionSettingsPage').default, } satisfies Screens; -const Stack = createSplitStackNavigator(); +const Split = createSplitNavigator(); function SettingsSplitNavigator() { const route = useRoute(); @@ -33,13 +33,13 @@ function SettingsSplitNavigator() { return ( - - ); })} - + ); } diff --git a/src/libs/Navigation/AppNavigator/Navigators/WorkspaceSplitNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/WorkspaceSplitNavigator.tsx index fd0c91757fa4..2d269e88ba16 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/WorkspaceSplitNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/WorkspaceSplitNavigator.tsx @@ -1,7 +1,7 @@ import {useRoute} from '@react-navigation/native'; import React from 'react'; import FocusTrapForScreens from '@components/FocusTrap/FocusTrapForScreen'; -import createSplitStackNavigator from '@libs/Navigation/AppNavigator/createSplitStackNavigator'; +import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import useRootNavigatorOptions from '@libs/Navigation/AppNavigator/useRootNavigatorOptions'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; @@ -29,7 +29,7 @@ const CENTRAL_PANE_WORKSPACE_SCREENS = { [SCREENS.WORKSPACE.RULES]: () => require('../../../../pages/workspace/rules/PolicyRulesPage').default, } satisfies Screens; -const Stack = createSplitStackNavigator(); +const Split = createSplitNavigator(); function WorkspaceNavigator() { const route = useRoute(); @@ -37,25 +37,25 @@ function WorkspaceNavigator() { return ( - - {Object.entries(CENTRAL_PANE_WORKSPACE_SCREENS).map(([screenName, componentGetter]) => ( - ))} - + ); } diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts similarity index 95% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts rename to src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts index 3bc1e50717ec..454b13f59417 100644 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/SplitStackRouter.ts +++ b/src/libs/Navigation/AppNavigator/createSplitNavigator/SplitRouter.ts @@ -5,7 +5,7 @@ import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import {getParamsFromRoute} from '@libs/Navigation/helpers'; import navigationRef from '@libs/Navigation/navigationRef'; import SCREENS from '@src/SCREENS'; -import type {SplitStackNavigatorRouterOptions} from './types'; +import type {SplitNavigatorRouterOptions} from './types'; import {getPreservedSplitNavigatorState} from './usePreserveSplitNavigatorState'; type StackState = StackNavigationState | PartialState>; @@ -14,7 +14,7 @@ const isAtLeastOneInState = (state: StackState, screenName: string): boolean => type AdaptStateIfNecessaryArgs = { state: StackState; - options: SplitStackNavigatorRouterOptions; + options: SplitNavigatorRouterOptions; }; function adaptStateIfNecessary({state, options: {sidebarScreen, defaultCentralScreen, parentRoute}}: AdaptStateIfNecessaryArgs) { @@ -83,14 +83,14 @@ function adaptStateIfNecessary({state, options: {sidebarScreen, defaultCentralSc } } -function isPushingSidebarOnCentralPane(state: StackState, action: CommonActions.Action | StackActionType, options: SplitStackNavigatorRouterOptions) { +function isPushingSidebarOnCentralPane(state: StackState, action: CommonActions.Action | StackActionType, options: SplitNavigatorRouterOptions) { if (action.type === 'PUSH' && action.payload.name === options.sidebarScreen && state.routes.length > 1) { return true; } return false; } -function SplitStackRouter(options: SplitStackNavigatorRouterOptions) { +function SplitRouter(options: SplitNavigatorRouterOptions) { const stackRouter = StackRouter(options); return { ...stackRouter, @@ -134,4 +134,4 @@ function SplitStackRouter(options: SplitStackNavigatorRouterOptions) { }; } -export default SplitStackRouter; +export default SplitRouter; diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/getInitialSplitNavigatorState.ts similarity index 100% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState.ts rename to src/libs/Navigation/AppNavigator/createSplitNavigator/getInitialSplitNavigatorState.ts diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createSplitNavigator/index.tsx similarity index 96% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/index.tsx rename to src/libs/Navigation/AppNavigator/createSplitNavigator/index.tsx index 629b48beaeb3..f04f51fcff41 100644 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createSplitNavigator/index.tsx @@ -11,7 +11,7 @@ import type { PlatformStackNavigationOptions, PlatformStackNavigationState, } from '@libs/Navigation/PlatformStackNavigation/types'; -import SplitStackRouter from './SplitStackRouter'; +import SplitRouter from './SplitRouter'; import usePreserveSplitNavigatorState from './usePreserveSplitNavigatorState'; function useCustomEffects(props: CustomEffectsHookProps) { @@ -35,7 +35,7 @@ function useCustomSplitNavigatorState({state}: CustomStateHookProps) { } const CustomFullScreenNavigatorComponent = createPlatformStackNavigatorComponent('CustomFullScreenNavigator', { - createRouter: SplitStackRouter, + createRouter: SplitRouter, useCustomEffects, defaultScreenOptions: defaultPlatformStackScreenOptions, useCustomState: useCustomSplitNavigatorState, diff --git a/src/libs/Navigation/AppNavigator/createSplitNavigator/types.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/types.ts new file mode 100644 index 000000000000..36da86e8f51a --- /dev/null +++ b/src/libs/Navigation/AppNavigator/createSplitNavigator/types.ts @@ -0,0 +1,11 @@ +import type {DefaultNavigatorOptions, ParamListBase, RouteProp, StackNavigationState, StackRouterOptions} from '@react-navigation/native'; +import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack'; + +type SplitNavigatorRouterOptions = StackRouterOptions & {defaultCentralScreen: string; sidebarScreen: string; parentRoute: RouteProp}; + +type SplitNavigatorProps = DefaultNavigatorOptions, StackNavigationOptions, StackNavigationEventMap> & { + defaultCentralScreen: Extract; + sidebarScreen: Extract; +}; + +export type {SplitNavigatorProps, SplitNavigatorRouterOptions}; diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useHandleScreenResize/index.native.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/useHandleScreenResize/index.native.ts similarity index 100% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/useHandleScreenResize/index.native.ts rename to src/libs/Navigation/AppNavigator/createSplitNavigator/useHandleScreenResize/index.native.ts diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useHandleScreenResize/index.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/useHandleScreenResize/index.ts similarity index 100% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/useHandleScreenResize/index.ts rename to src/libs/Navigation/AppNavigator/createSplitNavigator/useHandleScreenResize/index.ts diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/usePrepareSplitStackNavigatorChildren.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/usePrepareSplitStackNavigatorChildren.ts similarity index 88% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/usePrepareSplitStackNavigatorChildren.ts rename to src/libs/Navigation/AppNavigator/createSplitNavigator/usePrepareSplitStackNavigatorChildren.ts index 9609fa3ec994..4995f96bc1a4 100644 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/usePrepareSplitStackNavigatorChildren.ts +++ b/src/libs/Navigation/AppNavigator/createSplitNavigator/usePrepareSplitStackNavigatorChildren.ts @@ -3,7 +3,7 @@ import type {StackNavigationOptions} from '@react-navigation/stack'; import {Children, isValidElement, useMemo} from 'react'; import type {ReactNode} from 'react'; -export default function usePrepareSplitStackNavigatorChildren(screensNode: ReactNode, sidebarScreenName: string, sidebarScreenOptions: StackNavigationOptions) { +export default function usePrepareSplitNavigatorChildren(screensNode: ReactNode, sidebarScreenName: string, sidebarScreenOptions: StackNavigationOptions) { return useMemo( () => Children.toArray(screensNode).map((screen: ReactNode) => { diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/usePreserveSplitNavigatorState.ts b/src/libs/Navigation/AppNavigator/createSplitNavigator/usePreserveSplitNavigatorState.ts similarity index 100% rename from src/libs/Navigation/AppNavigator/createSplitStackNavigator/usePreserveSplitNavigatorState.ts rename to src/libs/Navigation/AppNavigator/createSplitNavigator/usePreserveSplitNavigatorState.ts diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/types.ts b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/types.ts deleted file mode 100644 index cc9db03c75ae..000000000000 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/types.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type {DefaultNavigatorOptions, ParamListBase, RouteProp, StackNavigationState, StackRouterOptions} from '@react-navigation/native'; -import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack'; - -type SplitStackNavigatorRouterOptions = StackRouterOptions & {defaultCentralScreen: string; sidebarScreen: string; parentRoute: RouteProp}; - -type SplitStackNavigatorProps = DefaultNavigatorOptions< - ParamListBase, - StackNavigationState, - StackNavigationOptions, - StackNavigationEventMap -> & { - defaultCentralScreen: Extract; - sidebarScreen: Extract; -}; - -export type {SplitStackNavigatorProps, SplitStackNavigatorRouterOptions}; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 865294ae0832..623ce67a3957 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -19,7 +19,7 @@ import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES'; import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import getInitialSplitNavigatorState from './AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState'; +import getInitialSplitNavigatorState from './AppNavigator/createSplitNavigator/getInitialSplitNavigatorState'; import { getMinimalAction, getPolicyIDFromState, diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 3181e2d60979..a8af25db8e62 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -22,7 +22,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import AppNavigator from './AppNavigator'; -import {cleanPreservedSplitNavigatorStates} from './AppNavigator/createSplitStackNavigator/usePreserveSplitNavigatorState'; +import {cleanPreservedSplitNavigatorStates} from './AppNavigator/createSplitNavigator/usePreserveSplitNavigatorState'; import {customGetPathFromState, getAdaptedStateFromPath, setupCustomAndroidBackHandler} from './helpers'; import linkingConfig from './linkingConfig'; import Navigation, {navigationRef} from './Navigation'; diff --git a/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts index c7a712f0fd7a..8a2886c36f27 100644 --- a/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/helpers/getAdaptedStateFromPath.ts @@ -2,7 +2,7 @@ import type {NavigationState, PartialState, Route} from '@react-navigation/nativ import {findFocusedRoute, getStateFromPath} from '@react-navigation/native'; import pick from 'lodash/pick'; import {isAnonymousUser} from '@libs/actions/Session'; -import getInitialSplitNavigatorState from '@libs/Navigation/AppNavigator/createSplitStackNavigator/getInitialSplitNavigatorState'; +import getInitialSplitNavigatorState from '@libs/Navigation/AppNavigator/createSplitNavigator/getInitialSplitNavigatorState'; import config from '@libs/Navigation/linkingConfig/config'; import RELATIONS from '@libs/Navigation/linkingConfig/RELATIONS'; import type {NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; diff --git a/src/pages/home/sidebar/BottomTabAvatar.tsx b/src/pages/home/sidebar/BottomTabAvatar.tsx index 0d93b3ff5a87..28712438aea9 100644 --- a/src/pages/home/sidebar/BottomTabAvatar.tsx +++ b/src/pages/home/sidebar/BottomTabAvatar.tsx @@ -8,7 +8,7 @@ import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; -import {getPreservedSplitNavigatorState} from '@libs/Navigation/AppNavigator/createSplitStackNavigator/usePreserveSplitNavigatorState'; +import {getPreservedSplitNavigatorState} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveSplitNavigatorState'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; import CONST from '@src/CONST'; From e69b8f0e8e84904691fe2a869ccea4f0d152b7a6 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 11:08:45 +0100 Subject: [PATCH 21/26] Fix tests that use useActiveWorkspace --- tests/perf-test/SidebarLinks.perf-test.tsx | 2 +- tests/ui/LHNItemsPresence.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/SidebarLinks.perf-test.tsx b/tests/perf-test/SidebarLinks.perf-test.tsx index b02d6e7e4640..3822afcfdee9 100644 --- a/tests/perf-test/SidebarLinks.perf-test.tsx +++ b/tests/perf-test/SidebarLinks.perf-test.tsx @@ -10,7 +10,7 @@ import wrapInAct from '../utils/wrapInActHelper'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; jest.mock('@libs/Permissions'); -jest.mock('@src/hooks/useActiveWorkspace', () => jest.fn(() => ({activeWorkspaceID: undefined}))); +jest.mock('@hooks/useActiveWorkspace', () => jest.fn(() => ({activeWorkspaceID: undefined}))); jest.mock('../../src/libs/Navigation/Navigation', () => ({ navigate: jest.fn(), isActiveRoute: jest.fn(), diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 6693c90adaa0..0b85327caa83 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -16,7 +16,7 @@ import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatch // Be sure to include the mocked permissions library, as some components that are rendered // during the test depend on its methods. jest.mock('@libs/Permissions'); -jest.mock('@src/hooks/useActiveWorkspaceFromNavigationState'); +jest.mock('@hooks/useActiveWorkspace', () => jest.fn(() => ({activeWorkspaceID: undefined}))); type LazyLoadLHNTestUtils = { fakePersonalDetails: PersonalDetailsList; From 28960319e574e9caba11c989494d73b02c3ebcd6 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 11:11:42 +0100 Subject: [PATCH 22/26] Fix mocking isSearchTopmostFullScreenRoute in IOUTest --- tests/actions/IOUTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index df37da0d15a0..65d2cc9de1db 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -34,7 +34,7 @@ jest.mock('@src/libs/Navigation/Navigation', () => ({ goBack: jest.fn(), })); -jest.mock('@src/libs/Navigation/isSearchTopmostFullScreenRoute', () => jest.fn()); +jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn()); const CARLOS_EMAIL = 'cmartins@expensifail.com'; const CARLOS_ACCOUNT_ID = 1; From 686dde6e15fcc8bf6c46a240f4bd83a441b0d151 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 11:47:46 +0100 Subject: [PATCH 23/26] Update relations files and remove redundant mappings --- .../RELATIONS/CENTRAL_PANE_TO_RHP_MAPPING.ts | 66 ----- .../RELATIONS/SEARCH_RHP_SCREENS.ts | 26 -- .../RELATIONS/SETTINGS_TO_RHP.ts | 3 + .../WORKSPACE_SCREEN_TO_RHP_MAPPING.ts | 252 ------------------ .../RELATIONS/WORKSPACE_TO_RHP.ts | 36 ++- 5 files changed, 38 insertions(+), 345 deletions(-) delete mode 100755 src/libs/Navigation/linkingConfig/RELATIONS/CENTRAL_PANE_TO_RHP_MAPPING.ts delete mode 100644 src/libs/Navigation/linkingConfig/RELATIONS/SEARCH_RHP_SCREENS.ts delete mode 100755 src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_SCREEN_TO_RHP_MAPPING.ts diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/CENTRAL_PANE_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/RELATIONS/CENTRAL_PANE_TO_RHP_MAPPING.ts deleted file mode 100755 index ca22a325f2f5..000000000000 --- a/src/libs/Navigation/linkingConfig/RELATIONS/CENTRAL_PANE_TO_RHP_MAPPING.ts +++ /dev/null @@ -1,66 +0,0 @@ -// @TODO: Remove this file before merging to the main. -import type {SplitNavigatorScreenName} from '@libs/Navigation/types'; -import SCREENS from '@src/SCREENS'; -import WORKSPACE_SCREEN_TO_RHP_MAPPING from './WORKSPACE_SCREEN_TO_RHP_MAPPING'; - -const CENTRAL_PANE_TO_RHP_MAPPING: Partial> = { - [SCREENS.SETTINGS.PROFILE.ROOT]: [ - SCREENS.SETTINGS.PROFILE.DISPLAY_NAME, - SCREENS.SETTINGS.PROFILE.CONTACT_METHODS, - SCREENS.SETTINGS.PROFILE.CONTACT_METHOD_DETAILS, - SCREENS.SETTINGS.PROFILE.NEW_CONTACT_METHOD, - SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER, - SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER_DATE, - SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER_TIME, - SCREENS.SETTINGS.PROFILE.STATUS, - SCREENS.SETTINGS.PROFILE.PRONOUNS, - SCREENS.SETTINGS.PROFILE.TIMEZONE, - SCREENS.SETTINGS.PROFILE.TIMEZONE_SELECT, - SCREENS.SETTINGS.PROFILE.LEGAL_NAME, - SCREENS.SETTINGS.PROFILE.DATE_OF_BIRTH, - SCREENS.SETTINGS.PROFILE.PHONE_NUMBER, - SCREENS.SETTINGS.PROFILE.ADDRESS, - SCREENS.SETTINGS.PROFILE.ADDRESS_COUNTRY, - SCREENS.SETTINGS.SHARE_CODE, - SCREENS.SETTINGS.EXIT_SURVEY.REASON, - SCREENS.SETTINGS.EXIT_SURVEY.RESPONSE, - SCREENS.SETTINGS.EXIT_SURVEY.CONFIRM, - ], - [SCREENS.SETTINGS.PREFERENCES.ROOT]: [SCREENS.SETTINGS.PREFERENCES.PRIORITY_MODE, SCREENS.SETTINGS.PREFERENCES.LANGUAGE, SCREENS.SETTINGS.PREFERENCES.THEME], - [SCREENS.SETTINGS.WALLET.ROOT]: [ - SCREENS.SETTINGS.WALLET.DOMAIN_CARD, - SCREENS.SETTINGS.WALLET.CARD_GET_PHYSICAL.NAME, - SCREENS.SETTINGS.WALLET.CARD_GET_PHYSICAL.PHONE, - SCREENS.SETTINGS.WALLET.CARD_GET_PHYSICAL.ADDRESS, - SCREENS.SETTINGS.WALLET.CARD_GET_PHYSICAL.CONFIRM, - SCREENS.SETTINGS.WALLET.TRANSFER_BALANCE, - SCREENS.SETTINGS.WALLET.CHOOSE_TRANSFER_ACCOUNT, - SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS, - SCREENS.SETTINGS.WALLET.CARD_ACTIVATE, - SCREENS.SETTINGS.WALLET.REPORT_VIRTUAL_CARD_FRAUD, - SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS, - ], - [SCREENS.SETTINGS.SECURITY]: [ - SCREENS.SETTINGS.TWO_FACTOR_AUTH, - SCREENS.SETTINGS.CLOSE, - SCREENS.SETTINGS.DELEGATE.ADD_DELEGATE, - SCREENS.SETTINGS.DELEGATE.DELEGATE_ROLE, - SCREENS.SETTINGS.DELEGATE.UPDATE_DELEGATE_ROLE, - SCREENS.SETTINGS.DELEGATE.DELEGATE_CONFIRM, - SCREENS.SETTINGS.DELEGATE.UPDATE_DELEGATE_ROLE_MAGIC_CODE, - ], - [SCREENS.SETTINGS.ABOUT]: [SCREENS.SETTINGS.APP_DOWNLOAD_LINKS], - [SCREENS.SETTINGS.SAVE_THE_WORLD]: [SCREENS.I_KNOW_A_TEACHER, SCREENS.INTRO_SCHOOL_PRINCIPAL, SCREENS.I_AM_A_TEACHER], - [SCREENS.SETTINGS.TROUBLESHOOT]: [SCREENS.SETTINGS.CONSOLE], - [SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: [ - SCREENS.SETTINGS.SUBSCRIPTION.ADD_PAYMENT_CARD, - SCREENS.SETTINGS.SUBSCRIPTION.SIZE, - SCREENS.SETTINGS.SUBSCRIPTION.DISABLE_AUTO_RENEW_SURVEY, - SCREENS.SETTINGS.SUBSCRIPTION.REQUEST_EARLY_CANCELLATION, - SCREENS.SETTINGS.SUBSCRIPTION.CHANGE_BILLING_CURRENCY, - SCREENS.SETTINGS.SUBSCRIPTION.CHANGE_PAYMENT_CURRENCY, - ], - ...WORKSPACE_SCREEN_TO_RHP_MAPPING, -}; - -export default CENTRAL_PANE_TO_RHP_MAPPING; diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/SEARCH_RHP_SCREENS.ts b/src/libs/Navigation/linkingConfig/RELATIONS/SEARCH_RHP_SCREENS.ts deleted file mode 100644 index 48422f90a7bc..000000000000 --- a/src/libs/Navigation/linkingConfig/RELATIONS/SEARCH_RHP_SCREENS.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @TODO Remove this file before merging to the main. -import SCREENS from '@src/SCREENS'; - -const SEARCH_RHP_SCREENS: string[] = [ - SCREENS.SEARCH.REPORT_RHP, - SCREENS.SEARCH.TRANSACTION_HOLD_REASON_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_CURRENCY_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_DATE_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_DESCRIPTION_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_MERCHANT_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_REPORT_ID_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_AMOUNT_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_CATEGORY_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_KEYWORD_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_TAX_RATE_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_EXPENSE_TYPE_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_TAG_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_FROM_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_TO_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_IN_RHP, - SCREENS.SEARCH.ADVANCED_FILTERS_CARD_RHP, - SCREENS.SEARCH.SAVED_SEARCH_RENAME_RHP, -]; - -export default SEARCH_RHP_SCREENS; diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts index 6e7c15ce3a16..1df3af0a6e86 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts @@ -17,6 +17,7 @@ const CENTRAL_PANE_TO_RHP_MAPPING: Partial> = { - [SCREENS.WORKSPACE.PROFILE]: [ - SCREENS.WORKSPACE.NAME, - SCREENS.WORKSPACE.ADDRESS, - SCREENS.WORKSPACE.CURRENCY, - SCREENS.WORKSPACE.DESCRIPTION, - SCREENS.WORKSPACE.SHARE, - SCREENS.WORKSPACE.DOWNGRADE, - ], - [SCREENS.WORKSPACE.MEMBERS]: [ - SCREENS.WORKSPACE.INVITE, - SCREENS.WORKSPACE.INVITE_MESSAGE, - SCREENS.WORKSPACE.MEMBER_DETAILS, - SCREENS.WORKSPACE.MEMBER_NEW_CARD, - SCREENS.WORKSPACE.OWNER_CHANGE_CHECK, - SCREENS.WORKSPACE.OWNER_CHANGE_SUCCESS, - SCREENS.WORKSPACE.OWNER_CHANGE_ERROR, - SCREENS.WORKSPACE.OWNER_CHANGE_ERROR, - SCREENS.WORKSPACE.MEMBERS_IMPORT, - SCREENS.WORKSPACE.MEMBERS_IMPORTED, - ], - [SCREENS.WORKSPACE.WORKFLOWS]: [ - SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_NEW, - SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_EDIT, - SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_EXPENSES_FROM, - SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_APPROVER, - SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY, - SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET, - SCREENS.WORKSPACE.WORKFLOWS_PAYER, - ], - [SCREENS.WORKSPACE.ACCOUNTING.ROOT]: [ - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_IMPORT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_CHART_OF_ACCOUNTS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_CLASSES, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_TAXES, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_LOCATIONS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_CUSTOMERS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_DATE_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_INVOICE_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT_COMPANY_CARD_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_PREFERRED_EXPORTER, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_NON_REIMBURSABLE_DEFAULT_VENDOR_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_ADVANCED, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_ACCOUNT_SELECTOR, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_INVOICE_ACCOUNT_SELECTOR, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_CLASSES_DISPLAYED_AS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_CUSTOMERS_DISPLAYED_AS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_LOCATIONS_DISPLAYED_AS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_COMPANY_CARD_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_NON_REIMBURSABLE_DEFAULT_VENDOR_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_ADVANCED, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_DATE_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_PREFERRED_EXPORTER, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_SETUP_MODAL, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_SETUP_REQUIRED_DEVICE_MODAL, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_TRIGGER_FIRST_SYNC, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_IMPORT, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_CHART_OF_ACCOUNTS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_CLASSES, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_CLASSES_DISPLAYED_AS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_CUSTOMERS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_CUSTOMERS_DISPLAYED_AS, - SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_ITEMS, - SCREENS.WORKSPACE.ACCOUNTING.XERO_IMPORT, - SCREENS.WORKSPACE.ACCOUNTING.XERO_CHART_OF_ACCOUNTS, - SCREENS.WORKSPACE.ACCOUNTING.XERO_ORGANIZATION, - SCREENS.WORKSPACE.ACCOUNTING.XERO_CUSTOMER, - SCREENS.WORKSPACE.ACCOUNTING.XERO_TAXES, - SCREENS.WORKSPACE.ACCOUNTING.XERO_TRACKING_CATEGORIES, - SCREENS.WORKSPACE.ACCOUNTING.XERO_MAP_TRACKING_CATEGORY, - SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT, - SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PURCHASE_BILL_DATE_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.XERO_ADVANCED, - SCREENS.WORKSPACE.ACCOUNTING.XERO_BILL_STATUS_SELECTOR, - SCREENS.WORKSPACE.ACCOUNTING.XERO_INVOICE_ACCOUNT_SELECTOR, - SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PREFERRED_EXPORTER_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.XERO_BILL_PAYMENT_ACCOUNT_SELECTOR, - SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_BANK_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_SUBSIDIARY_SELECTOR, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_REUSE_EXISTING_CONNECTIONS, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_TOKEN_INPUT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_MAPPING, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_FIELD, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_FIELD_VIEW, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_FIELD_EDIT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_LIST_ADD, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOM_SEGMENT_ADD, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOMERS_OR_PROJECTS, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_IMPORT_CUSTOMERS_OR_PROJECTS_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_PREFERRED_EXPORTER_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_DATE_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT_EXPENSES, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT_EXPENSES_DESTINATION_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT_EXPENSES_VENDOR_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT_EXPENSES_PAYABLE_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT_EXPENSES_JOURNAL_POSTING_PREFERENCE_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_RECEIVABLE_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_INVOICE_ITEM_PREFERENCE_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_INVOICE_ITEM_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_TAX_POSTING_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_PROVINCIAL_TAX_POSTING_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_ADVANCED, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_REIMBURSEMENT_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_COLLECTION_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPENSE_REPORT_APPROVAL_LEVEL_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_VENDOR_BILL_APPROVAL_LEVEL_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_JOURNAL_ENTRY_APPROVAL_LEVEL_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_APPROVAL_ACCOUNT_SELECT, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_CUSTOM_FORM_ID, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_AUTO_SYNC, - SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_ACCOUNTING_METHOD, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_PREREQUISITES, - SCREENS.WORKSPACE.ACCOUNTING.ENTER_SAGE_INTACCT_CREDENTIALS, - SCREENS.WORKSPACE.ACCOUNTING.EXISTING_SAGE_INTACCT_CONNECTIONS, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_ENTITY, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_IMPORT, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_MAPPING_TYPE, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_TOGGLE_MAPPING, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_USER_DIMENSIONS, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_ADD_USER_DIMENSION, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EDIT_USER_DIMENSION, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EXPORT, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_PREFERRED_EXPORTER, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EXPORT_DATE, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_EXPENSES, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_DESTINATION, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_DEFAULT_VENDOR, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_ADVANCED, - SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_PAYMENT_ACCOUNT, - SCREENS.WORKSPACE.ACCOUNTING.CARD_RECONCILIATION, - SCREENS.WORKSPACE.ACCOUNTING.RECONCILIATION_ACCOUNT_SETTINGS, - ], - [SCREENS.WORKSPACE.TAXES]: [ - SCREENS.WORKSPACE.TAXES_SETTINGS, - SCREENS.WORKSPACE.TAX_CREATE, - SCREENS.WORKSPACE.TAXES_SETTINGS_CUSTOM_TAX_NAME, - SCREENS.WORKSPACE.TAXES_SETTINGS_FOREIGN_CURRENCY_DEFAULT, - SCREENS.WORKSPACE.TAXES_SETTINGS_WORKSPACE_CURRENCY_DEFAULT, - SCREENS.WORKSPACE.TAX_CREATE, - SCREENS.WORKSPACE.TAX_EDIT, - SCREENS.WORKSPACE.TAX_NAME, - SCREENS.WORKSPACE.TAX_VALUE, - SCREENS.WORKSPACE.TAX_CODE, - ], - [SCREENS.WORKSPACE.TAGS]: [ - SCREENS.WORKSPACE.TAGS_SETTINGS, - SCREENS.WORKSPACE.TAGS_EDIT, - SCREENS.WORKSPACE.TAG_CREATE, - SCREENS.WORKSPACE.TAG_SETTINGS, - SCREENS.WORKSPACE.TAG_EDIT, - SCREENS.WORKSPACE.TAG_LIST_VIEW, - SCREENS.WORKSPACE.TAG_GL_CODE, - SCREENS.WORKSPACE.TAG_APPROVER, - SCREENS.WORKSPACE.TAGS_IMPORT, - SCREENS.WORKSPACE.TAGS_IMPORTED, - ], - [SCREENS.WORKSPACE.CATEGORIES]: [ - SCREENS.WORKSPACE.CATEGORY_CREATE, - SCREENS.WORKSPACE.CATEGORY_SETTINGS, - SCREENS.WORKSPACE.CATEGORIES_IMPORT, - SCREENS.WORKSPACE.CATEGORIES_IMPORTED, - SCREENS.WORKSPACE.CATEGORIES_SETTINGS, - SCREENS.WORKSPACE.CATEGORY_EDIT, - SCREENS.WORKSPACE.CATEGORY_GL_CODE, - SCREENS.WORKSPACE.CATEGORY_PAYROLL_CODE, - SCREENS.WORKSPACE.CATEGORY_DEFAULT_TAX_RATE, - SCREENS.WORKSPACE.CATEGORY_FLAG_AMOUNTS_OVER, - SCREENS.WORKSPACE.CATEGORY_DESCRIPTION_HINT, - SCREENS.WORKSPACE.CATEGORY_APPROVER, - SCREENS.WORKSPACE.CATEGORY_REQUIRE_RECEIPTS_OVER, - ], - [SCREENS.WORKSPACE.DISTANCE_RATES]: [ - SCREENS.WORKSPACE.CREATE_DISTANCE_RATE, - SCREENS.WORKSPACE.DISTANCE_RATES_SETTINGS, - SCREENS.WORKSPACE.DISTANCE_RATE_EDIT, - SCREENS.WORKSPACE.DISTANCE_RATE_TAX_RECLAIMABLE_ON_EDIT, - SCREENS.WORKSPACE.DISTANCE_RATE_TAX_RATE_EDIT, - SCREENS.WORKSPACE.DISTANCE_RATE_DETAILS, - ], - [SCREENS.WORKSPACE.REPORT_FIELDS]: [ - SCREENS.WORKSPACE.REPORT_FIELDS_CREATE, - SCREENS.WORKSPACE.REPORT_FIELDS_SETTINGS, - SCREENS.WORKSPACE.REPORT_FIELDS_LIST_VALUES, - SCREENS.WORKSPACE.REPORT_FIELDS_ADD_VALUE, - SCREENS.WORKSPACE.REPORT_FIELDS_VALUE_SETTINGS, - SCREENS.WORKSPACE.REPORT_FIELDS_EDIT_VALUE, - SCREENS.WORKSPACE.REPORT_FIELDS_EDIT_INITIAL_VALUE, - ], - [SCREENS.WORKSPACE.INVOICES]: [SCREENS.WORKSPACE.INVOICES_COMPANY_NAME, SCREENS.WORKSPACE.INVOICES_COMPANY_WEBSITE], - [SCREENS.WORKSPACE.COMPANY_CARDS]: [ - SCREENS.WORKSPACE.COMPANY_CARDS_SELECT_FEED, - SCREENS.WORKSPACE.COMPANY_CARDS_ADD_NEW, - SCREENS.WORKSPACE.COMPANY_CARDS_TYPE, - SCREENS.WORKSPACE.COMPANY_CARDS_INSTRUCTIONS, - SCREENS.WORKSPACE.COMPANY_CARDS_NAME, - SCREENS.WORKSPACE.COMPANY_CARDS_DETAILS, - SCREENS.WORKSPACE.COMPANY_CARDS_SELECT_FEED, - SCREENS.WORKSPACE.COMPANY_CARDS_SETTINGS, - SCREENS.WORKSPACE.COMPANY_CARDS_SETTINGS_FEED_NAME, - SCREENS.WORKSPACE.COMPANY_CARDS_SETTINGS, - SCREENS.WORKSPACE.COMPANY_CARDS_SETTINGS_FEED_NAME, - SCREENS.WORKSPACE.COMPANY_CARDS_ASSIGN_CARD, - SCREENS.WORKSPACE.COMPANY_CARD_DETAILS, - SCREENS.WORKSPACE.COMPANY_CARD_NAME, - SCREENS.WORKSPACE.COMPANY_CARD_EXPORT, - ], - [SCREENS.WORKSPACE.EXPENSIFY_CARD]: [ - SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW, - SCREENS.WORKSPACE.EXPENSIFY_CARD_BANK_ACCOUNT, - SCREENS.WORKSPACE.EXPENSIFY_CARD_SETTINGS, - SCREENS.WORKSPACE.EXPENSIFY_CARD_SETTINGS_ACCOUNT, - SCREENS.WORKSPACE.EXPENSIFY_CARD_SETTINGS_FREQUENCY, - SCREENS.WORKSPACE.EXPENSIFY_CARD_DETAILS, - SCREENS.WORKSPACE.EXPENSIFY_CARD_NAME, - SCREENS.WORKSPACE.EXPENSIFY_CARD_LIMIT, - SCREENS.WORKSPACE.EXPENSIFY_CARD_LIMIT_TYPE, - ], - [SCREENS.WORKSPACE.RULES]: [ - SCREENS.WORKSPACE.RULES_CUSTOM_NAME, - SCREENS.WORKSPACE.RULES_AUTO_APPROVE_REPORTS_UNDER, - SCREENS.WORKSPACE.RULES_RANDOM_REPORT_AUDIT, - SCREENS.WORKSPACE.RULES_AUTO_PAY_REPORTS_UNDER, - SCREENS.WORKSPACE.RULES_RECEIPT_REQUIRED_AMOUNT, - SCREENS.WORKSPACE.RULES_MAX_EXPENSE_AMOUNT, - SCREENS.WORKSPACE.RULES_MAX_EXPENSE_AGE, - SCREENS.WORKSPACE.RULES_BILLABLE_DEFAULT, - ], - [SCREENS.WORKSPACE.PER_DIEM]: [SCREENS.WORKSPACE.PER_DIEM_IMPORT, SCREENS.WORKSPACE.PER_DIEM_IMPORTED, SCREENS.WORKSPACE.PER_DIEM_SETTINGS], -}; - -export default WORKSPACE_SCREEN_TO_RHP_MAPPING; diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts index fd492cd85800..1c4f684a9aed 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts @@ -3,7 +3,14 @@ import SCREENS from '@src/SCREENS'; // This file is used to define relation between workspace split navigator's central screens and RHP screens. const WORKSPACE_TO_RHP: Partial> = { - [SCREENS.WORKSPACE.PROFILE]: [SCREENS.WORKSPACE.NAME, SCREENS.WORKSPACE.ADDRESS, SCREENS.WORKSPACE.CURRENCY, SCREENS.WORKSPACE.DESCRIPTION, SCREENS.WORKSPACE.SHARE], + [SCREENS.WORKSPACE.PROFILE]: [ + SCREENS.WORKSPACE.NAME, + SCREENS.WORKSPACE.ADDRESS, + SCREENS.WORKSPACE.CURRENCY, + SCREENS.WORKSPACE.DESCRIPTION, + SCREENS.WORKSPACE.SHARE, + SCREENS.WORKSPACE.DOWNGRADE, + ], [SCREENS.WORKSPACE.MEMBERS]: [ SCREENS.WORKSPACE.INVITE, SCREENS.WORKSPACE.INVITE_MESSAGE, @@ -46,6 +53,30 @@ const WORKSPACE_TO_RHP: Partial Date: Wed, 11 Dec 2024 13:00:58 +0100 Subject: [PATCH 24/26] Add popToTop method to Navigation.ts --- src/libs/Navigation/Navigation.ts | 30 +++++++++---------- .../navigateAfterJoinRequest/index.desktop.ts | 2 +- src/libs/navigateAfterJoinRequest/index.ts | 2 +- .../navigateAfterJoinRequest/index.web.ts | 2 +- .../AddBankAccount/AddBankAccount.tsx | 4 +-- src/pages/EnablePayments/EnablePayments.tsx | 2 +- src/pages/home/ReportScreen.tsx | 4 +-- src/pages/workspace/WorkspaceJoinUserPage.tsx | 2 +- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 623ce67a3957..81daa35e5768 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -202,17 +202,10 @@ type GoBackOptions = { * In that case we want to goUp to a country picker with any params so we don't compare them. */ compareParams?: boolean; - - /** - * Specifies whether goBack should pop to top when invoked. - * Additionaly, to execute popToTop, set the value of the global variable ShouldPopAllStateOnUP to true using the setShouldPopAllStateOnUP function. - */ - shouldPopToTop?: boolean; }; const defaultGoBackOptions: Required = { compareParams: true, - shouldPopToTop: false, }; /** @@ -274,21 +267,13 @@ function goUp(fallbackRoute: Route, options?: GoBackOptions) { /** * @param fallbackRoute - Fallback route if pop/goBack action should, but is not possible within RHP - * @param options - Optional configuration that affects navigation logic, e.g. whether goBack should popToTop. + * @param options - Optional configuration that affects navigation logic. */ function goBack(fallbackRoute?: Route, options?: GoBackOptions) { if (!canNavigate('goBack')) { return; } - if (options?.shouldPopToTop) { - if (shouldPopAllStateOnUP) { - shouldPopAllStateOnUP = false; - navigationRef.current?.dispatch(StackActions.popToTop()); - return; - } - } - if (fallbackRoute) { goUp(fallbackRoute, options); return; @@ -485,6 +470,18 @@ const dismissModalWithReport = (report: OnyxEntry) => { isNavigationReady().then(() => navigateToReportWithPolicyCheck({report})); }; +/** + * Returns to the first screen in the stack, dismissing all the others, only if the global variable shouldPopAllStateOnUP is set to true. + */ +function popToTop() { + if (!shouldPopAllStateOnUP) { + return; + } + + shouldPopAllStateOnUP = false; + navigationRef.current?.dispatch(StackActions.popToTop()); +} + export default { setShouldPopAllStateOnUP, navigate, @@ -508,6 +505,7 @@ export default { closeRHPFlow, setNavigationActionToMicrotaskQueue, navigateToReportWithPolicyCheck, + popToTop, }; export {navigationRef}; diff --git a/src/libs/navigateAfterJoinRequest/index.desktop.ts b/src/libs/navigateAfterJoinRequest/index.desktop.ts index 9b72ee30de57..461f5376e6c1 100644 --- a/src/libs/navigateAfterJoinRequest/index.desktop.ts +++ b/src/libs/navigateAfterJoinRequest/index.desktop.ts @@ -4,7 +4,7 @@ import ROUTES from '@src/ROUTES'; const navigateAfterJoinRequest = () => { // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToTop(); if (getIsSmallScreenWidth()) { Navigation.navigate(ROUTES.SETTINGS); } diff --git a/src/libs/navigateAfterJoinRequest/index.ts b/src/libs/navigateAfterJoinRequest/index.ts index a3ac50cd59be..91b2fdade606 100644 --- a/src/libs/navigateAfterJoinRequest/index.ts +++ b/src/libs/navigateAfterJoinRequest/index.ts @@ -3,7 +3,7 @@ import ROUTES from '@src/ROUTES'; const navigateAfterJoinRequest = () => { // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToTop(); Navigation.navigate(ROUTES.SETTINGS); Navigation.navigate(ROUTES.SETTINGS_WORKSPACES); }; diff --git a/src/libs/navigateAfterJoinRequest/index.web.ts b/src/libs/navigateAfterJoinRequest/index.web.ts index 9b72ee30de57..461f5376e6c1 100644 --- a/src/libs/navigateAfterJoinRequest/index.web.ts +++ b/src/libs/navigateAfterJoinRequest/index.web.ts @@ -4,7 +4,7 @@ import ROUTES from '@src/ROUTES'; const navigateAfterJoinRequest = () => { // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToTop(); if (getIsSmallScreenWidth()) { Navigation.navigate(ROUTES.SETTINGS); } diff --git a/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx b/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx index 060d5664ac93..a273b210efa9 100644 --- a/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx +++ b/src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx @@ -52,7 +52,7 @@ function AddBankAccount() { PaymentMethods.continueSetup(onSuccessFallbackRoute); return; } - Navigation.goBack(ROUTES.SETTINGS_WALLET, {shouldPopToTop: true}); + Navigation.goBack(ROUTES.SETTINGS_WALLET); }; const handleBackButtonPress = () => { @@ -63,7 +63,7 @@ function AddBankAccount() { if (screenIndex === 0) { BankAccounts.clearPersonalBankAccount(); Wallet.updateCurrentStep(null); - Navigation.goBack(ROUTES.SETTINGS_WALLET, {shouldPopToTop: true}); + Navigation.goBack(ROUTES.SETTINGS_WALLET); return; } prevScreen(); diff --git a/src/pages/EnablePayments/EnablePayments.tsx b/src/pages/EnablePayments/EnablePayments.tsx index b8aeb4103a59..742202e43bb3 100644 --- a/src/pages/EnablePayments/EnablePayments.tsx +++ b/src/pages/EnablePayments/EnablePayments.tsx @@ -46,7 +46,7 @@ function EnablePaymentsPage() { > Navigation.goBack(ROUTES.SETTINGS_WALLET, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET)} /> diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 0f80147cbfa4..be0b049e67d0 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -295,7 +295,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro return; } // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToTop(); }, [isInNarrowPaneModal]); let headerView = ( @@ -592,7 +592,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro if (Navigation.getTopmostReportId() === prevOnyxReportID) { Navigation.setShouldPopAllStateOnUP(true); // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToTop(); } if (prevReport?.parentReportID) { // Prevent navigation to the IOU/Expense Report if it is pending deletion. diff --git a/src/pages/workspace/WorkspaceJoinUserPage.tsx b/src/pages/workspace/WorkspaceJoinUserPage.tsx index 66caff7263ef..6e8333d75451 100644 --- a/src/pages/workspace/WorkspaceJoinUserPage.tsx +++ b/src/pages/workspace/WorkspaceJoinUserPage.tsx @@ -47,7 +47,7 @@ function WorkspaceJoinUserPage({route, policy}: WorkspaceJoinUserPageProps) { Navigation.isNavigationReady().then(() => { // @TODO: Check if this method works the same as on the main branch // NOTE: It probably doesn't need any params. When this method is called, shouldPopAllStateOnUP is always false - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToTop(); Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID ?? '-1')); }); return; From 097d3c5a024ae14fa38279f32b5067032d73036b Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 13:23:33 +0100 Subject: [PATCH 25/26] Unification of comments in Navigation.ts --- src/libs/Navigation/Navigation.ts | 95 +++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 81daa35e5768..94b2df4aa957 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -36,15 +36,6 @@ import RELATIONS from './linkingConfig/RELATIONS'; import navigationRef from './navigationRef'; import type {NavigationPartialRoute, NavigationStateRoute, RootStackParamList, State} from './types'; -// Get the sidebar screen parameters from the split navigator passed as a param -function getSidebarScreenParams(splitNavigatorRoute: NavigationStateRoute) { - if (splitNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { - return splitNavigatorRoute.state?.routes?.at(0)?.params; - } - - return undefined; -} - let resolveNavigationIsReadyPromise: () => void; const navigationIsReadyPromise = new Promise((resolve) => { resolveNavigationIsReadyPromise = resolve; @@ -61,6 +52,21 @@ function setShouldPopAllStateOnUP(shouldPopAllStateFlag: boolean) { shouldPopAllStateOnUP = shouldPopAllStateFlag; } +/** + * @private + * Get the sidebar screen parameters from the split navigator passed as a param. + */ +function getSidebarScreenParams(splitNavigatorRoute: NavigationStateRoute) { + if (splitNavigatorRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { + return splitNavigatorRoute.state?.routes?.at(0)?.params; + } + + return undefined; +} + +/** + * Checks if the navigationRef is ready to perform a method. + */ function canNavigate(methodName: string, params: Record = {}): boolean { if (navigationRef.isReady()) { return true; @@ -69,16 +75,24 @@ function canNavigate(methodName: string, params: Record = {}): return false; } -// Extracts from the topmost report its id. +/** + * Extracts from the topmost report its id. + */ const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID; -// Extracts from the topmost report its action id. +/** + * Extracts from the topmost report its action id. + */ const getTopmostReportActionId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportActionID; -// Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies. +/** + * Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies. + */ const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref); -// Function that generates dynamic urls from paths passed from OldDot. +/** + * Function that generates dynamic urls from paths passed from OldDot. + */ function parseHybridAppUrl(url: HybridAppRoute | Route): Route { switch (url) { case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL: @@ -93,7 +107,9 @@ function parseHybridAppUrl(url: HybridAppRoute | Route): Route { } } -// Returns the current active route. +/** + * Returns the current active route. + */ function getActiveRoute(): string { const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute(); if (!currentRoute?.name) { @@ -108,7 +124,9 @@ function getActiveRoute(): string { return ''; } -// Returns the route of a report opened in RHP. +/** + * Returns the route of a report opened in RHP. + */ function getReportRHPActiveRoute(): string { if (isReportOpenInRHP(navigationRef.getRootState())) { return getActiveRoute(); @@ -155,11 +173,18 @@ function navigate(route: Route = ROUTES.HOME, type?: string) { */ const routeParamsIgnore = ['path', 'initial', 'params', 'state', 'screen', 'policyID']; -// If we use destructuring, we will get an error if any of the ignored properties are not present in the object. +/** + * @private + * If we use destructuring, we will get an error if any of the ignored properties are not present in the object. + */ function getRouteParamsToCompare(routeParams: Record) { return omit(routeParams, routeParamsIgnore); } +/** + * @private + * Private method used in goUp to determine whether a target route is present in the navigation state. + */ function doesRouteMatchToMinimalActionPayload(route: NavigationStateRoute | NavigationPartialRoute, minimalAction: Writable, compareParams: boolean) { if (!minimalAction.payload) { return false; @@ -189,7 +214,10 @@ function doesRouteMatchToMinimalActionPayload(route: NavigationStateRoute | Navi return shallowCompare(routeParams, minimalActionParams); } -// Checks whether the given state is the root navigator state +/** + * @private + * Checks whether the given state is the root navigator state + */ function isRootNavigatorState(state: State): state is State { return state.key === navigationRef.current?.getRootState().key; } @@ -209,6 +237,7 @@ const defaultGoBackOptions: Required = { }; /** + * @private * Navigate to the given fallbackRoute taking into account whether it is possible to go back to this screen. Within one nested navigator, we can go back by any number * of screens, but if as a result of going back we would have to remove more than one screen from the rootState, * replace is performed so as not to lose the visited pages. @@ -267,7 +296,7 @@ function goUp(fallbackRoute: Route, options?: GoBackOptions) { /** * @param fallbackRoute - Fallback route if pop/goBack action should, but is not possible within RHP - * @param options - Optional configuration that affects navigation logic. + * @param options - Optional configuration that affects navigation logic */ function goBack(fallbackRoute?: Route, options?: GoBackOptions) { if (!canNavigate('goBack')) { @@ -305,7 +334,9 @@ function goBack(fallbackRoute?: Route, options?: GoBackOptions) { navigationRef.current?.goBack(); } -// Reset the navigation state to Home page +/** + * Reset the navigation state to Home page. + */ function resetToHome() { const isNarrowLayout = getIsNarrowLayout(); const rootState = navigationRef.getRootState(); @@ -319,7 +350,9 @@ function resetToHome() { navigationRef.dispatch({payload, type: 'REPLACE', target: rootState.key}); } -// Update route params for the specified route. +/** + * Update route params for the specified route. + */ function setParams(params: Record, routeKey = '') { navigationRef.current?.dispatch({ ...CommonActions.setParams(params), @@ -327,12 +360,16 @@ function setParams(params: Record, routeKey = '') { }); } -// Returns the current active route without the URL params. +/** + * Returns the current active route without the URL params. + */ function getActiveRouteWithoutParams(): string { return getActiveRoute().replace(/\?.*/, ''); } -// Returns the active route name from a state event from the navigationRef. +/** + * Returns the active route name from a state event from the navigationRef. + */ function getRouteNameFromStateEvent(event: EventArg<'state', false, NavigationContainerEventMap['state']['data']>): string | undefined { if (!event.data.state) { return; @@ -346,6 +383,7 @@ function getRouteNameFromStateEvent(event: EventArg<'state', false, NavigationCo } /** + * @private * Navigate to the route that we originally intended to go to * but the NavigationContainer was not ready when navigate() was called */ @@ -368,6 +406,7 @@ function setIsNavigationReady() { } /** + * @private * Checks if the navigation state contains routes that are protected (over the auth wall). * * @param state - react-navigation state object @@ -412,7 +451,9 @@ function waitForProtectedRoutes() { }); } -// Changes the currently selected policy in the app. +/** + * Changes the currently selected policy in the app. + */ function switchPolicyID(policyID?: string) { navigationRef.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID, payload: {policyID}}); } @@ -455,7 +496,9 @@ function navigateToReportWithPolicyCheck({report, reportID, reportActionID, refe ); } -// Closes the modal navigator (RHP, LHP, onboarding). +/** + * Closes the modal navigator (RHP, LHP, onboarding). + */ const dismissModal = (reportID?: string, ref = navigationRef) => { ref.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL}); if (!reportID) { @@ -464,7 +507,9 @@ const dismissModal = (reportID?: string, ref = navigationRef) => { isNavigationReady().then(() => navigateToReportWithPolicyCheck({reportID})); }; -// Dismisses the modal and opens the given report. +/** + * Dismisses the modal and opens the given report. + */ const dismissModalWithReport = (report: OnyxEntry) => { dismissModal(); isNavigationReady().then(() => navigateToReportWithPolicyCheck({report})); From 0ae4aac4184dc1f420bd5a91b83beec5eefb830c Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 11 Dec 2024 13:56:26 +0100 Subject: [PATCH 26/26] Fix goBack in navigateToConciergeChatAndDeleteReport --- src/libs/actions/Report.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index e62891dba5cb..8e675fd9fee2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2418,11 +2418,13 @@ function deleteReport(reportID: string, shouldDeleteChildReports = false) { */ function navigateToConciergeChatAndDeleteReport(reportID: string, shouldPopToTop = false, shouldDeleteChildReports = false) { // Dismiss the current report screen and replace it with Concierge Chat + // @TODO: Check if this method works the same as on the main branch if (shouldPopToTop) { Navigation.setShouldPopAllStateOnUP(true); + Navigation.popToTop(); + } else { + Navigation.goBack(); } - // @TODO: Check if this method works the same as on the main branch - Navigation.goBack(undefined, {shouldPopToTop}); navigateToConciergeChat(); InteractionManager.runAfterInteractions(() => { deleteReport(reportID, shouldDeleteChildReports);