Skip to content

Commit

Permalink
Fix navigation issues across platforms
Browse files Browse the repository at this point in the history
Signed-off-by: Tsaqif <[email protected]>
  • Loading branch information
tsa321 committed Aug 25, 2024
1 parent 1a1e96d commit f7d800b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type GetAdaptedStateReturnType = {
metainfo: Metainfo;
};

type GetAdaptedStateFromPath = (...args: Parameters<typeof getStateFromPath>) => GetAdaptedStateReturnType;
type GetAdaptedStateFromPath = (...args: [...Parameters<typeof getStateFromPath>, 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<NavigationState> => ({routes, index: routes.length - 1});
Expand Down Expand Up @@ -365,7 +365,7 @@ function getAdaptedState(state: PartialState<NavigationState<RootStackParamList>
};
}

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();
Expand All @@ -374,7 +374,9 @@ const getAdaptedStateFromPath: GetAdaptedStateFromPath = (path, options) => {
const policyID = isAnonymous ? undefined : extractPolicyIDFromPath(path);

const state = getStateFromPath(pathWithoutPolicyID, options) as PartialState<NavigationState<RootStackParamList>>;
replacePathInNestedState(state, path);
if (shouldReplacePathInNestedState) {
replacePathInNestedState(state, path);
}
if (state === undefined) {
throw new Error('Unable to parse path');
}
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,7 @@ function openReportFromDeepLink(url: string) {
});
});
}

function getCurrentUserAccountID(): number {
return currentUserAccountID;
}
Expand Down
12 changes: 3 additions & 9 deletions src/libs/actions/Welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f7d800b

Please sign in to comment.