Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update getPartialStateDiff.ts fullscreen diff #39442

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/libs/Navigation/AppNavigator/getPartialStateDiff.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getTopmostBottomTabRoute from '@libs/Navigation/getTopmostBottomTabRoute';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
import getTopmostFullScreenRoute from '@libs/Navigation/getTopmostFullScreenRoute';
import type {Metainfo} from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath';
import type {NavigationPartialRoute, RootStackParamList, State} from '@libs/Navigation/types';
import NAVIGATORS from '@src/NAVIGATORS';
Expand Down Expand Up @@ -73,10 +74,19 @@ function getPartialStateDiff(state: State<RootStackParamList>, templateState: St
// 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.
// For now this simple check is enough.
if (metainfo.isFullScreenNavigatorMandatory) {
const stateTopmostFullScreen = state.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1);
const templateStateTopmostFullScreen = templateState.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1) as NavigationPartialRoute;
if (!stateTopmostFullScreen && templateStateTopmostFullScreen) {
diff[NAVIGATORS.FULL_SCREEN_NAVIGATOR] = templateStateTopmostFullScreen;
const stateTopmostFullScreen = getTopmostFullScreenRoute(state);
const templateStateTopmostFullScreen = getTopmostFullScreenRoute(templateState);
const fullScreenDiff = templateState.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1) as NavigationPartialRoute;

if (
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(!stateTopmostFullScreen && templateStateTopmostFullScreen) ||
(stateTopmostFullScreen &&
templateStateTopmostFullScreen &&
stateTopmostFullScreen.name !== templateStateTopmostFullScreen.name &&
!shallowCompare(stateTopmostFullScreen.params, templateStateTopmostFullScreen.params))
Comment on lines +86 to +87
Copy link
Contributor Author

@ahmedGaber93 ahmedGaber93 Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using && here cause the issue appear again after change the FullScreenNavigator structures here #40342, and it fixed here #43992

) {
diff[NAVIGATORS.FULL_SCREEN_NAVIGATOR] = fullScreenDiff;
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/libs/Navigation/getTopmostFullScreenRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import NAVIGATORS from '@src/NAVIGATORS';
import type {FullScreenName, NavigationPartialRoute, RootStackParamList, State} from './types';

// Get the name of topmost fullscreen route in the navigation stack.
function getTopmostFullScreenRoute(state: State<RootStackParamList>): NavigationPartialRoute<FullScreenName> | undefined {
if (!state) {
return;
}

const topmostFullScreenRoute = state.routes.filter((route) => route.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR).at(-1);

if (!topmostFullScreenRoute) {
return;
}

if (!!topmostFullScreenRoute.params && 'screen' in topmostFullScreenRoute.params) {
return {name: topmostFullScreenRoute.params.screen as FullScreenName, params: topmostFullScreenRoute.params.params};
}

if (!topmostFullScreenRoute.state) {
return;
}

// There will be at least one route in the fullscreen navigator.
const {name, params} = topmostFullScreenRoute.state.routes.at(-1) as NavigationPartialRoute<FullScreenName>;

return {name, params};
}

export default getTopmostFullScreenRoute;
Loading