Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 31688 Notification preferences page appears again after refreshing the page #31702

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,40 @@ function getDistanceFromPathInRootNavigator(path) {
return -1;
}

/**
* Returns the current active route
* @returns {String}
*/
function getActiveRoute() {
const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute();
const currentRouteHasName = lodashGet(currentRoute, 'name', false);
if (!currentRouteHasName) {
return '';
}

const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config);

if (routeFromState) {
return routeFromState;
}

return '';
}

/**
* Check whether the passed route is currently Active or not.
*
* Building path with getPathFromState since navigationRef.current.getCurrentRoute().path
* is undefined in the first navigation.
*
* @param {String} routePath Path to check
* @return {Boolean} is active
*/
function isActiveRoute(routePath) {
// We remove First forward slash from the URL before matching
return getActiveRoute().substring(1) === routePath;
}

/**
* Main navigation method for redirecting to a route.
* @param {String} route
Expand All @@ -111,7 +145,7 @@ function navigate(route = ROUTES.HOME, type) {
pendingRoute = route;
return;
}
linkTo(navigationRef.current, route, type);
linkTo(navigationRef.current, route, type, isActiveRoute(route));
}

/**
Expand Down Expand Up @@ -221,26 +255,6 @@ function dismissModal(targetReportID) {
}
}

/**
* Returns the current active route
* @returns {String}
*/
function getActiveRoute() {
const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute();
const currentRouteHasName = lodashGet(currentRoute, 'name', false);
if (!currentRouteHasName) {
return '';
}

const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config);

if (routeFromState) {
return routeFromState;
}

return '';
}

/**
* Returns the current active route without the URL params
* @returns {String}
Expand All @@ -265,20 +279,6 @@ function getRouteNameFromStateEvent(event) {
}
}

/**
* Check whether the passed route is currently Active or not.
*
* Building path with getPathFromState since navigationRef.current.getCurrentRoute().path
* is undefined in the first navigation.
*
* @param {String} routePath Path to check
* @return {Boolean} is active
*/
function isActiveRoute(routePath) {
// We remove First forward slash from the URL before matching
return getActiveRoute().substring(1) === routePath;
}

/**
* Navigate to the route that we originally intended to go to
* but the NavigationContainer was not ready when navigate() was called
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Navigation/linkTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getMinimalAction(action, state) {
return currentAction;
}

export default function linkTo(navigation, path, type) {
export default function linkTo(navigation, path, type, isActiveRoute) {
if (navigation === undefined) {
throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?");
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function linkTo(navigation, path, type) {
// There are situations where a route already exists on the current navigation stack
// But we want to push the same route instead of going back in the stack
// Which would break the user navigation history
if (type === CONST.NAVIGATION.ACTION_TYPE.PUSH) {
if (!isActiveRoute && type === CONST.NAVIGATION.ACTION_TYPE.PUSH) {
minimalAction.type = CONST.NAVIGATION.ACTION_TYPE.PUSH;
}
// There are situations when the user is trying to access a route which he has no access to
Expand Down
Loading