Skip to content

Commit

Permalink
Merge pull request #31702 from tienifr/fix/31688
Browse files Browse the repository at this point in the history
fix: 31688 Notification preferences page appears again after refreshing the page
  • Loading branch information
luacmartins authored Nov 22, 2023
2 parents 8417724 + b6abdd4 commit 2e88d28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
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

0 comments on commit 2e88d28

Please sign in to comment.