diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useNavigationReset/index.native.ts b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useNavigationReset/index.native.ts deleted file mode 100644 index 5d5d30356781..000000000000 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useNavigationReset/index.native.ts +++ /dev/null @@ -1 +0,0 @@ -export default function useNavigationReset() {} diff --git a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useNavigationReset/index.ts b/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useNavigationReset/index.ts deleted file mode 100644 index 238fc1ca2928..000000000000 --- a/src/libs/Navigation/AppNavigator/createSplitStackNavigator/useNavigationReset/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type {NavigationHelpers, ParamListBase} from '@react-navigation/native'; -import {useEffect} from 'react'; -import navigationRef from '@libs/Navigation/navigationRef'; - -export default function useNavigationReset(navigation: NavigationHelpers, isSmallScreenWidth: boolean) { - useEffect(() => { - if (!navigationRef.isReady()) { - return; - } - // We need to separately reset state of this navigator to trigger getRehydratedState. - navigation.reset(navigation.getState()); - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [isSmallScreenWidth]); -} diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 92b739ff8879..ed13a2076537 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -26,12 +26,12 @@ import originalGetTopmostReportActionId from './getTopmostReportActionID'; import originalGetTopmostReportId from './getTopmostReportId'; import isReportOpenInRHP from './isReportOpenInRHP'; import linkingConfig from './linkingConfig'; +import createSplitNavigator from './linkingConfig/createSplitNavigator'; 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, StateOrRoute} from './types'; -import createSplitNavigator from './linkingConfig/createSplitNavigator'; const SPLIT_NAVIGATOR_TO_SIDEBAR_MAP: Record = { [NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]: SCREENS.HOME, diff --git a/src/libs/Navigation/linkingConfig/SEARCH_RHP_SCREENS.ts b/src/libs/Navigation/linkingConfig/SEARCH_RHP_SCREENS.ts deleted file mode 100644 index e61622f808bc..000000000000 --- a/src/libs/Navigation/linkingConfig/SEARCH_RHP_SCREENS.ts +++ /dev/null @@ -1,24 +0,0 @@ -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, -]; - -export default SEARCH_RHP_SCREENS; diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 07352a7b6d85..07dc2863c3ca 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -21,9 +21,6 @@ type GetAdaptedStateReturnType = { type GetAdaptedStateFromPath = (...args: [...Parameters, shouldReplacePathInNestedState?: boolean]) => GetAdaptedStateReturnType; -type SplitNavigatorLHNScreen = keyof typeof mapLhnToSplitNavigatorName; -type SplitNavigator = (typeof mapLhnToSplitNavigatorName)[SplitNavigatorLHNScreen]; - // 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}); diff --git a/src/libs/Navigation/newLinkTo/getActionForBottomTabNavigator.ts b/src/libs/Navigation/newLinkTo/getActionForBottomTabNavigator.ts deleted file mode 100644 index 85580d068ad7..000000000000 --- a/src/libs/Navigation/newLinkTo/getActionForBottomTabNavigator.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type {NavigationAction, NavigationState} from '@react-navigation/native'; -import type {Writable} from 'type-fest'; -import type {RootStackParamList, StackNavigationAction} from '@libs/Navigation/types'; -import getTopmostBottomTabRoute from '@navigation/getTopmostBottomTabRoute'; -import CONST from '@src/CONST'; -import type {ActionPayloadParams} from './types'; - -// Because we need to change the type to push, we also need to set target for this action to the bottom tab navigator. -function getActionForBottomTabNavigator( - action: StackNavigationAction, - state: NavigationState, - policyID?: string, - shouldNavigate?: boolean, -): Writable | undefined { - const bottomTabNavigatorRoute = state.routes.at(0); - if (!bottomTabNavigatorRoute || bottomTabNavigatorRoute.state === undefined || !action || action.type !== CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) { - return; - } - - const params = action.payload.params as ActionPayloadParams; - let payloadParams = params.params as Record; - const screen = params.screen; - - if (policyID && !payloadParams?.policyID) { - payloadParams = {...payloadParams, policyID}; - } else if (!policyID) { - delete payloadParams?.policyID; - } - - // Check if the current bottom tab is the same as the one we want to navigate to. If it is, we don't need to do anything. - const bottomTabCurrentTab = getTopmostBottomTabRoute(state); - const bottomTabParams = bottomTabCurrentTab?.params as Record; - - // Verify if the policyID is different than the one we are currently on. If it is, we need to navigate to the new policyID. - const isNewPolicy = bottomTabParams?.policyID !== payloadParams?.policyID; - if (bottomTabCurrentTab?.name === screen && !shouldNavigate && !isNewPolicy) { - return; - } - - return { - type: CONST.NAVIGATION.ACTION_TYPE.PUSH, - payload: { - name: screen, - params: payloadParams, - }, - target: bottomTabNavigatorRoute.state.key, - }; -} - -export default getActionForBottomTabNavigator; diff --git a/src/libs/Navigation/newLinkTo/index.ts b/src/libs/Navigation/newLinkTo/index.ts deleted file mode 100644 index 40d51cd6ec9f..000000000000 --- a/src/libs/Navigation/newLinkTo/index.ts +++ /dev/null @@ -1,61 +0,0 @@ -import {getActionFromState} from '@react-navigation/core'; -import type {NavigationContainerRef, NavigationState, PartialState} from '@react-navigation/native'; -import {findFocusedRoute} from '@react-navigation/native'; -import {shallowCompare} from '@libs/ObjectUtils'; -import {getPathWithoutPolicyID} from '@libs/PolicyUtils'; -import getStateFromPath from '@navigation/getStateFromPath'; -import linkingConfig from '@navigation/linkingConfig'; -import type {RootStackParamList, StackNavigationAction} from '@navigation/types'; -import CONST from '@src/CONST'; -import type {Route} from '@src/ROUTES'; -import getMinimalAction from './getMinimalAction'; - -function shouldDispatchAction(currentState: NavigationState, stateFromPath: PartialState>) { - const currentFocusedRoute = findFocusedRoute(currentState); - const targetFocusedRoute = findFocusedRoute(stateFromPath); - - const areNamesEqual = currentFocusedRoute?.name === targetFocusedRoute?.name; - const areParamsEqual = shallowCompare(currentFocusedRoute?.params as Record | undefined, targetFocusedRoute?.params as Record | undefined); - - if (areNamesEqual && areParamsEqual) { - return false; - } - - return true; -} - -export default function linkTo(navigation: NavigationContainerRef | null, path: Route, type?: typeof CONST.NAVIGATION.ACTION_TYPE.REPLACE) { - if (!navigation) { - throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?"); - } - - const pathWithoutPolicyID = getPathWithoutPolicyID(`/${path}`) as Route; - - // This is the state generated with the default getStateFromPath function. - // It won't include the whole state that will be generated for this path but the focused route will be correct. - // It is necessary because getActionFromState will generate RESET action for whole state generated with our custom getStateFromPath function. - const stateFromPath = getStateFromPath(pathWithoutPolicyID) as PartialState>; - const currentState = navigation.getRootState() as NavigationState; - const action: StackNavigationAction = getActionFromState(stateFromPath, linkingConfig.config); - - // We don't want to dispatch action to push/replace with exactly the same route that is already focused. - if (!shouldDispatchAction(currentState, stateFromPath)) { - return; - } - - // If there is no action, just reset the whole state. - if (!action) { - navigation.resetRoot(stateFromPath); - return; - } - - if (type === CONST.NAVIGATION.ACTION_TYPE.REPLACE) { - action.type = CONST.NAVIGATION.ACTION_TYPE.REPLACE; - } else if (action.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) { - // We want to PUSH by default to add entries to the browser history. - action.type = CONST.NAVIGATION.ACTION_TYPE.PUSH; - } - - const {action: minimalAction} = getMinimalAction(action, navigation.getRootState()); - navigation.dispatch(minimalAction); -} diff --git a/src/libs/Navigation/newLinkTo/types.ts b/src/libs/Navigation/newLinkTo/types.ts deleted file mode 100644 index 254a4cdef2a5..000000000000 --- a/src/libs/Navigation/newLinkTo/types.ts +++ /dev/null @@ -1,11 +0,0 @@ -type ActionPayloadParams = { - screen?: string; - params?: unknown; - path?: string; -}; - -type ActionPayload = { - params?: ActionPayloadParams; -}; - -export type {ActionPayload, ActionPayloadParams}; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index ba9ca736a2f6..6e2e2526e8de 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -60,8 +60,6 @@ type SplitNavigatorParamListType = { [NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR]: WorkspaceSplitNavigatorParamList; }; -type SplitNavigatorName = keyof SplitNavigatorParamListType; - type SplitNavigatorByLHN = (typeof LHN_TO_SPLIT_NAVIGATOR_NAME)[T]; type CentralPaneScreensParamList = { @@ -1652,5 +1650,4 @@ export type { SplitNavigatorLHNScreen, SplitNavigatorParamListType, SplitNavigatorByLHN, - SplitNavigatorName, }; diff --git a/src/pages/settings/InitialSettingsPage.tsx b/src/pages/settings/InitialSettingsPage.tsx index 4a014fdcfb25..32ca20741d07 100755 --- a/src/pages/settings/InitialSettingsPage.tsx +++ b/src/pages/settings/InitialSettingsPage.tsx @@ -413,7 +413,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr scrollEventThrottle={16} contentContainerStyle={[styles.w100]} showsVerticalScrollIndicator={false} - > + > {accountMenuItems} {workspaceMenuItems} {generalMenuItems}