Skip to content

Commit 7ce153d

Browse files
committed
Fix wrong goUp behavior after migration
1 parent 24f8e47 commit 7ce153d

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,6 +5230,7 @@ const CONST = {
52305230
REPLACE: 'REPLACE',
52315231
PUSH: 'PUSH',
52325232
NAVIGATE: 'NAVIGATE',
5233+
NAVIGATE_DEPRECATED: 'NAVIGATE_DEPRECATED',
52335234
SET_PARAMS: 'SET_PARAMS',
52345235

52355236
/** These action types are custom for RootNavigator */

src/libs/Navigation/Navigation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ function goUp(backToRoute: Route, options?: GoBackOptions) {
305305
return;
306306
}
307307

308+
/**
309+
* In react-navigation 7 the behavior of the `navigate` function has slightly changed.
310+
* If it detects that a screen that we want to navigate to is already in the stack, it doesn't go back anymore.
311+
* More: https://reactnavigation.org/docs/upgrading-from-6.x#the-navigate-method-no-longer-goes-back-use-popto-instead
312+
*/
313+
if (minimalAction.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) {
314+
minimalAction.type = CONST.NAVIGATION.ACTION_TYPE.NAVIGATE_DEPRECATED
315+
}
316+
308317
const indexOfBackToRoute = targetState.routes.findLastIndex((route) => doesRouteMatchToMinimalActionPayload(route, minimalAction, compareParams));
309318
const distanceToPop = targetState.routes.length - indexOfBackToRoute - 1;
310319

0 commit comments

Comments
 (0)