From b3ee9c62c5b62f144d30f6508eb2cf51607a0f9b Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 19 Jun 2024 14:43:07 +0200 Subject: [PATCH 1/7] Add isReportInRhpOpened --- src/libs/Navigation/linkTo/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index 6cec46eae144..458137f4cbb3 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -21,7 +21,7 @@ import getAdaptedStateFromPath from '@navigation/linkingConfig/getAdaptedStateFr import getMatchingBottomTabRouteForState from '@navigation/linkingConfig/getMatchingBottomTabRouteForState'; import getMatchingCentralPaneRouteForState from '@navigation/linkingConfig/getMatchingCentralPaneRouteForState'; import replacePathInNestedState from '@navigation/linkingConfig/replacePathInNestedState'; -import type {NavigationRoot, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; +import type {NavigationPartialRoute, NavigationRoot, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import type {Route} from '@src/ROUTES'; @@ -51,10 +51,11 @@ export default function linkTo(navigation: NavigationContainerRef)?.policyID ?? '') !== ((matchingBottomTabRoute?.params as Record)?.policyID ?? ''); + const isReportInRhpOpened = + lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && lastRoute?.state?.routes?.includes((route: NavigationPartialRoute) => route?.name === SCREENS.SEARCH.REPORT_RHP); if (topmostBottomTabRoute && (topmostBottomTabRoute.name !== matchingBottomTabRoute.name || isNewPolicyID || isOpeningSearch)) { root.dispatch({ @@ -98,7 +101,8 @@ export default function linkTo(navigation: NavigationContainerRef Date: Wed, 19 Jun 2024 14:48:27 +0200 Subject: [PATCH 2/7] Refactor docs --- src/libs/Navigation/linkTo/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index 458137f4cbb3..b1f45e6b32f4 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -101,7 +101,7 @@ export default function linkTo(navigation: NavigationContainerRef Date: Wed, 19 Jun 2024 15:50:11 +0200 Subject: [PATCH 3/7] Refactor handling isReportInRhpOpened --- src/libs/Navigation/linkTo/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index b1f45e6b32f4..6fee4600885d 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -67,6 +67,9 @@ export default function linkTo(navigation: NavigationContainerRef route?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT); + // If action type is different than NAVIGATE we can't change it to the PUSH safely if (action?.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) { const topRouteName = lastRoute?.name; @@ -91,8 +94,6 @@ export default function linkTo(navigation: NavigationContainerRef)?.policyID ?? '') !== ((matchingBottomTabRoute?.params as Record)?.policyID ?? ''); - const isReportInRhpOpened = - lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && lastRoute?.state?.routes?.includes((route: NavigationPartialRoute) => route?.name === SCREENS.SEARCH.REPORT_RHP); if (topmostBottomTabRoute && (topmostBottomTabRoute.name !== matchingBottomTabRoute.name || isNewPolicyID || isOpeningSearch)) { root.dispatch({ @@ -101,8 +102,7 @@ export default function linkTo(navigation: NavigationContainerRef Date: Wed, 19 Jun 2024 16:20:37 +0200 Subject: [PATCH 4/7] Refactor check isReportInRhpOpened --- src/libs/Navigation/linkingConfig/customGetPathFromState.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts index 3ae1ed245ec6..5ebc1d5c1889 100644 --- a/src/libs/Navigation/linkingConfig/customGetPathFromState.ts +++ b/src/libs/Navigation/linkingConfig/customGetPathFromState.ts @@ -18,6 +18,7 @@ const removePolicyIDParamFromState = (state: State) => { }; const customGetPathFromState: typeof getPathFromState = (state, options) => { + console.log('state', state); // For the Home and Settings pages 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); From d9dc3d78433d5450a50fbe5c71de4374f5637de7 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 19 Jun 2024 16:22:34 +0200 Subject: [PATCH 5/7] Refactor check isReportInRhpOpened --- src/libs/Navigation/linkTo/index.ts | 10 +++++----- .../Navigation/linkingConfig/customGetPathFromState.ts | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index 6fee4600885d..a523a8e12067 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -205,12 +205,12 @@ export default function linkTo(navigation: NavigationContainerRef) => { }; const customGetPathFromState: typeof getPathFromState = (state, options) => { - console.log('state', state); // For the Home and Settings pages 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); From ed788a07d23705ddf95151c09ce9890689465bc4 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Wed, 19 Jun 2024 16:28:50 +0200 Subject: [PATCH 6/7] Fix types in linkTo --- src/libs/Navigation/linkTo/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index a523a8e12067..c652a87a80db 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -21,7 +21,7 @@ import getAdaptedStateFromPath from '@navigation/linkingConfig/getAdaptedStateFr import getMatchingBottomTabRouteForState from '@navigation/linkingConfig/getMatchingBottomTabRouteForState'; import getMatchingCentralPaneRouteForState from '@navigation/linkingConfig/getMatchingCentralPaneRouteForState'; import replacePathInNestedState from '@navigation/linkingConfig/replacePathInNestedState'; -import type {NavigationPartialRoute, NavigationRoot, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; +import type {NavigationRoot, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import type {Route} from '@src/ROUTES'; @@ -67,8 +67,7 @@ export default function linkTo(navigation: NavigationContainerRef route?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT); + const isReportInRhpOpened = lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && lastRoute?.state?.routes?.some((route) => route?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT); // If action type is different than NAVIGATE we can't change it to the PUSH safely if (action?.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) { From 296e8ddce84c7ebafe926440060ef2ef33571acb Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 20 Jun 2024 16:37:54 +0200 Subject: [PATCH 7/7] Refactor check isReportInRhpOpened --- src/libs/Navigation/linkTo/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index c652a87a80db..7e49c1613a62 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -204,12 +204,12 @@ export default function linkTo(navigation: NavigationContainerRef