Skip to content

Commit 0ddfa64

Browse files
fix: replace HOME instead of pushing when navigating to Settings RHP
when navigating from HOME to an RHP that maps to a different fullscreen (e.g. Settings Wallet), replace HOME with the matching fullscreen instead of pushing on top. pushing creates [HOME, SETTINGS_SPLIT_NAVIGATOR, RHP] which causes Android to trim HOME from the render tree, producing wrong back animation (#85122). the original fix in #87128 added a blanket guard in shouldChangeToMatchingFullScreen that returned false for HOME, which broke Add address navigation (#87655). replacing HOME matches the reload state shape [SETTINGS, RHP] and fixes both issues: correct back animation AND working navigation. removes the blanket guard in shouldChangeToMatchingFullScreen so the replace path can run.
1 parent fb1ed57 commit 0ddfa64

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

  • src/libs/Navigation/helpers/linkTo

src/libs/Navigation/helpers/linkTo/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ function shouldChangeToMatchingFullScreen(
9494
lastFullScreenRoute: NavigationPartialRoute,
9595
) {
9696
if (matchingFullScreenRoute.name !== lastFullScreenRoute.name) {
97-
// HOME has no RHP children (HOME_TO_RHP maps to []).
98-
// Pushing another fullscreen under HOME causes Android to trim HOME
99-
// from the render tree, reversing the back animation direction.
100-
if (lastFullScreenRoute.name === SCREENS.HOME) {
101-
return false;
102-
}
10397
return true;
10498
}
10599

@@ -174,15 +168,20 @@ export default function linkTo(navigation: NavigationContainerRef<RootNavigatorP
174168

175169
const lastFullScreenRoute = currentState.routes.findLast((route) => isFullScreenName(route.name));
176170
if (matchingFullScreenRoute && lastFullScreenRoute && shouldChangeToMatchingFullScreen(newFocusedRoute, matchingFullScreenRoute, lastFullScreenRoute as NavigationPartialRoute)) {
171+
// When navigating from HOME to an RHP that maps to a different fullscreen (e.g. Settings),
172+
// replace HOME instead of pushing on top. Pushing creates [HOME, SETTINGS, RHP] which causes
173+
// Android's useCustomRootStackNavigatorState to trim HOME from the render tree, producing
174+
// a wrong back animation. Replacing matches the reload state shape: [SETTINGS, RHP].
175+
const shouldReplace = lastFullScreenRoute.name === SCREENS.HOME;
177176
if (isRoutePreloaded(currentState, matchingFullScreenRoute)) {
178-
navigation.dispatch(StackActions.push(matchingFullScreenRoute.name));
177+
navigation.dispatch(shouldReplace ? StackActions.replace(matchingFullScreenRoute.name) : StackActions.push(matchingFullScreenRoute.name));
179178
} else {
180179
const lastRouteInMatchingFullScreen = matchingFullScreenRoute.state?.routes?.at(-1);
181-
const additionalAction = StackActions.push(matchingFullScreenRoute.name, {
180+
const routeParams = {
182181
screen: lastRouteInMatchingFullScreen?.name,
183182
params: lastRouteInMatchingFullScreen?.params,
184-
});
185-
navigation.dispatch(additionalAction);
183+
};
184+
navigation.dispatch(shouldReplace ? StackActions.replace(matchingFullScreenRoute.name, routeParams) : StackActions.push(matchingFullScreenRoute.name, routeParams));
186185
}
187186
}
188187
}

0 commit comments

Comments
 (0)