From f7d800bc0cfd6c243f5853fb6b6c80585589082a Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Sun, 25 Aug 2024 09:35:02 +0700 Subject: [PATCH] Fix navigation issues across platforms Signed-off-by: Tsaqif --- .../linkingConfig/getAdaptedStateFromPath.ts | 8 +++++--- src/libs/actions/Report.ts | 1 + src/libs/actions/Welcome.ts | 12 +++--------- .../BaseOnboardingPersonalDetails.tsx | 4 +++- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 611831544bdc..16bb1c89b6e8 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -47,7 +47,7 @@ type GetAdaptedStateReturnType = { metainfo: Metainfo; }; -type GetAdaptedStateFromPath = (...args: Parameters) => GetAdaptedStateReturnType; +type GetAdaptedStateFromPath = (...args: [...Parameters, shouldReplacePathInNestedState?: boolean]) => GetAdaptedStateReturnType; // 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}); @@ -365,7 +365,7 @@ function getAdaptedState(state: PartialState }; } -const getAdaptedStateFromPath: GetAdaptedStateFromPath = (path, options) => { +const getAdaptedStateFromPath: GetAdaptedStateFromPath = (path, options, shouldReplacePathInNestedState = true) => { const normalizedPath = !path.startsWith('/') ? `/${path}` : path; const pathWithoutPolicyID = getPathWithoutPolicyID(normalizedPath); const isAnonymous = isAnonymousUser(); @@ -374,7 +374,9 @@ const getAdaptedStateFromPath: GetAdaptedStateFromPath = (path, options) => { const policyID = isAnonymous ? undefined : extractPolicyIDFromPath(path); const state = getStateFromPath(pathWithoutPolicyID, options) as PartialState>; - replacePathInNestedState(state, path); + if (shouldReplacePathInNestedState) { + replacePathInNestedState(state, path); + } if (state === undefined) { throw new Error('Unable to parse path'); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 6307d69949fa..9a8f41ef9c3a 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2722,6 +2722,7 @@ function openReportFromDeepLink(url: string) { }); }); } + function getCurrentUserAccountID(): number { return currentUserAccountID; } diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 9c02f64452bc..5bc515184464 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -168,7 +168,7 @@ function updateOnboardingLastVisitedPath(path: string) { function getOnboardingInitialPath(): Route { const state = getStateFromPath(onboardingInitialPath as Route); if (state?.routes?.at(-1)?.name !== NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR) { - return ROUTES.ONBOARDING_ROOT.getRoute() as Route; + return ROUTES.ONBOARDING_ROOT.route as Route; } return onboardingInitialPath as Route; @@ -203,14 +203,8 @@ function completeHybridAppOnboarding() { } function startOnboardingFlow() { - const currentState = navigationRef.getRootState(); - if (currentState?.routes?.at(-1)?.name === NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR) { - Navigation.closeAndNavigate(getOnboardingInitialPath()); - } else { - const {adaptedState} = getAdaptedStateFromPath(ROUTES.ONBOARDING_ROOT.route, linkingConfig.config); - navigationRef.resetRoot(adaptedState); - Navigation.navigate(getOnboardingInitialPath()); - } + const {adaptedState} = getAdaptedStateFromPath(getOnboardingInitialPath(), linkingConfig.config, false); + navigationRef.resetRoot(adaptedState); } Onyx.connect({ diff --git a/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx b/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx index 4e3ebd6d0578..04dce7f826ab 100644 --- a/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx +++ b/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx @@ -75,7 +75,9 @@ function BaseOnboardingPersonalDetails({ Welcome.setOnboardingAdminsChatReportID(); Welcome.setOnboardingPolicyID(); - Navigation.dismissModal(); + // Navigate to HOME instead of dismissModal, because there is bug in small screen + // where the onboarding puropose page will be disaplayed briefly + Navigation.navigate(ROUTES.HOME); // Only navigate to concierge chat when central pane is visible // Otherwise stay on the chats screen.