Skip to content

Commit 9d00358

Browse files
authored
Merge pull request #39442 from ahmedGaber93/issue-39288
update getPartialStateDiff.ts fullscreen diff
2 parents 2456975 + 220d866 commit 9d00358

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/libs/Navigation/AppNavigator/getPartialStateDiff.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute';
22
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
3+
import getTopmostFullScreenRoute from '@libs/Navigation/getTopmostFullScreenRoute';
34
import type {Metainfo} from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath';
45
import type {NavigationPartialRoute, RootStackParamList, State} from '@libs/Navigation/types';
56
import NAVIGATORS from '@src/NAVIGATORS';
@@ -73,10 +74,19 @@ function getPartialStateDiff(state: State<RootStackParamList>, templateState: St
7374
// This one is heuristic and may need to be improved if we will be able to navigate from modal screen with full screen in background to another modal screen with full screen in background.
7475
// For now this simple check is enough.
7576
if (metainfo.isFullScreenNavigatorMandatory) {
76-
const stateTopmostFullScreen = state.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1);
77-
const templateStateTopmostFullScreen = templateState.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1) as NavigationPartialRoute;
78-
if (!stateTopmostFullScreen && templateStateTopmostFullScreen) {
79-
diff[NAVIGATORS.FULL_SCREEN_NAVIGATOR] = templateStateTopmostFullScreen;
77+
const stateTopmostFullScreen = getTopmostFullScreenRoute(state);
78+
const templateStateTopmostFullScreen = getTopmostFullScreenRoute(templateState);
79+
const fullScreenDiff = templateState.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1) as NavigationPartialRoute;
80+
81+
if (
82+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
83+
(!stateTopmostFullScreen && templateStateTopmostFullScreen) ||
84+
(stateTopmostFullScreen &&
85+
templateStateTopmostFullScreen &&
86+
stateTopmostFullScreen.name !== templateStateTopmostFullScreen.name &&
87+
!shallowCompare(stateTopmostFullScreen.params, templateStateTopmostFullScreen.params))
88+
) {
89+
diff[NAVIGATORS.FULL_SCREEN_NAVIGATOR] = fullScreenDiff;
8090
}
8191
}
8292

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import NAVIGATORS from '@src/NAVIGATORS';
2+
import type {FullScreenName, NavigationPartialRoute, RootStackParamList, State} from './types';
3+
4+
// Get the name of topmost fullscreen route in the navigation stack.
5+
function getTopmostFullScreenRoute(state: State<RootStackParamList>): NavigationPartialRoute<FullScreenName> | undefined {
6+
if (!state) {
7+
return;
8+
}
9+
10+
const topmostFullScreenRoute = state.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1);
11+
12+
if (!topmostFullScreenRoute) {
13+
return;
14+
}
15+
16+
if (!!topmostFullScreenRoute.params && 'screen' in topmostFullScreenRoute.params) {
17+
return {name: topmostFullScreenRoute.params.screen as FullScreenName, params: topmostFullScreenRoute.params.params};
18+
}
19+
20+
if (!topmostFullScreenRoute.state) {
21+
return;
22+
}
23+
24+
// There will be at least one route in the fullscreen navigator.
25+
const {name, params} = topmostFullScreenRoute.state.routes.at(-1) as NavigationPartialRoute<FullScreenName>;
26+
27+
return {name, params};
28+
}
29+
30+
export default getTopmostFullScreenRoute;

0 commit comments

Comments
 (0)