Skip to content
Open
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
11 changes: 8 additions & 3 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref);
/**
* Close the side panel on narrow layout when navigating to a different screen.
*/
function closeSidePanelOnNarrowScreen() {
function closeSidePanelOnNarrowScreen(route: Route) {
const isExtraLargeScreenWidth = Dimensions.get('window').width > variables.sidePanelResponsiveWidthBreakpoint;
const attachmentRoutePrefix = ROUTES.REPORT_ADD_ATTACHMENT.route.split(':').at(0) ?? ''; // "r/"
const isAttachmentPreviewRoute = typeof route === 'string' && route.includes('/attachment/add') && route.startsWith(attachmentRoutePrefix);
Comment on lines +190 to +191
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to apply this to REPORT_ATTACHMENTS as well, otherwise we'll see the same issue when opening the attachment page. And move this below the first condition so the check is skipped when we know it can never occur.

Suggested change
const attachmentRoutePrefix = ROUTES.REPORT_ADD_ATTACHMENT.route.split(':').at(0) ?? ''; // "r/"
const isAttachmentPreviewRoute = typeof route === 'string' && route.includes('/attachment/add') && route.startsWith(attachmentRoutePrefix);
// Split "r/:reportID/attachment/add" by ":reportID" to get the prefix "r/" and suffix "/attachment/add"
const addAttachmentPrefix = ROUTES.REPORT_ADD_ATTACHMENT.route.split(':reportID').at(0) ?? '';
const addAttachmentSuffix = ROUTES.REPORT_ADD_ATTACHMENT.route.split(':reportID').at(1) ?? '';
const attachmentPreviewRoute = ROUTES.REPORT_ATTACHMENTS.route;
const isAddingAttachment = typeof route === 'string' && route.startsWith(addAttachmentPrefix) && route.includes(addAttachmentSuffix);
const isPreviewingAttachment = typeof route === 'string' && route.startsWith(attachmentPreviewRoute);
// If the user is navigating to an attachment route (previewing or adding), keep the side panel open
// so they still have access to the chat.
if (isAddingAttachment || isPreviewingAttachment) {
return;
}


if (!sidePanelNVP?.openNarrowScreen || isExtraLargeScreenWidth) {
// If we have a side panel open on devices smaller than 1300px and the user wants to go to the REPORT_ADD_ATTACHMENT route,
// this means that the user clicked `Add Attachments` in the side panel, and in this case,
// there is no need to close the side panel, as we need to have access to the chat.
if (!sidePanelNVP?.openNarrowScreen || isExtraLargeScreenWidth || isAttachmentPreviewRoute) {
return;
}
SidePanelActions.closeSidePanel(true);
Expand Down Expand Up @@ -308,7 +313,7 @@ function navigate(route: Route, options?: LinkToOptions) {

const targetRoute = route.startsWith(CONST.SAML_REDIRECT_URL) ? ROUTES.HOME : route;
linkTo(navigationRef.current, targetRoute, options);
closeSidePanelOnNarrowScreen();
closeSidePanelOnNarrowScreen(route);
}
/**
* When routes are compared to determine whether the fallback route passed to the goUp function is in the state,
Expand Down
Loading