Skip to content

Commit 1d677d6

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). but the original fix (blocking the fullscreen change entirely) broke Add address navigation (#87655). replacing HOME matches the reload state shape [SETTINGS, RHP] and fixes both issues: correct back animation AND working navigation.
1 parent 647e27e commit 1d677d6

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • src/libs/Navigation/helpers/linkTo

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,22 @@ export default function linkTo(navigation: NavigationContainerRef<RootNavigatorP
168168

169169
const lastFullScreenRoute = currentState.routes.findLast((route) => isFullScreenName(route.name));
170170
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;
171176
if (isRoutePreloaded(currentState, matchingFullScreenRoute)) {
172-
navigation.dispatch(StackActions.push(matchingFullScreenRoute.name));
177+
navigation.dispatch(shouldReplace ? StackActions.replace(matchingFullScreenRoute.name) : StackActions.push(matchingFullScreenRoute.name));
173178
} else {
174179
const lastRouteInMatchingFullScreen = matchingFullScreenRoute.state?.routes?.at(-1);
175-
const additionalAction = StackActions.push(matchingFullScreenRoute.name, {
180+
const routeParams = {
176181
screen: lastRouteInMatchingFullScreen?.name,
177182
params: lastRouteInMatchingFullScreen?.params,
178-
});
179-
navigation.dispatch(additionalAction);
183+
};
184+
navigation.dispatch(
185+
shouldReplace ? StackActions.replace(matchingFullScreenRoute.name, routeParams) : StackActions.push(matchingFullScreenRoute.name, routeParams),
186+
);
180187
}
181188
}
182189
}

0 commit comments

Comments
 (0)