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

fix: Attachments reopen on multiple 'esc' click and hang on browser's navigation back #31524

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function ComposerWithSuggestions({
InputFocus.inputFocusChange(false);
return;
}
focus();
focus(true);
}, [focus, prevIsFocused, editFocused, prevIsModalVisible, isFocused, modal.isVisible, isNextModalWillOpenRef]);
useEffect(() => {
// Scrolls the composer to the bottom and sets the selection to the end, so that longer drafts are easier to edit
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/report/ReportAttachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React, {useCallback} from 'react';
import _ from 'underscore';
import AttachmentModal from '@components/AttachmentModal';
import ComposerFocusManager from '@libs/ComposerFocusManager';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -38,7 +39,11 @@ function ReportAttachments(props) {
defaultOpen
report={report}
source={source}
onModalHide={() => Navigation.dismissModal()}
onModalHide={() => {
Navigation.dismissModal();
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abdulrahuman5196 I decided to go with my alternative solution for the Composer refocus on navigation because removing the !fullscreen check in hideModal would cause a regression on the Composer refocus after closing the Emoji picker.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this change? What does change bring in? @paultsimura

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This focuses the composer when we navigate back by clicking the browser's "Back" button. Otherwise, ComposerFocusManager.setReadyToFocus() is called within BaseModal in 2 places:

const handleDismissModal = () => {
ComposerFocusManager.setReadyToFocus();
};

if (!fullscreen) {
ComposerFocusManager.setReadyToFocus();
}

The AttachmentsModal is fullscreen, so the hideModal does not call the ComposerFocusManager.setReadyToFocus().
Also, the Modal's onDismiss is not called when we are navigating – it's the RN limitation. The component just gets destroyed without calling the onDismiss.
Therefore, the ComposerFocusManager.setReadyToFocus() is not called in these two places in the BaseModal, so we need to call it explicitly.

}}
onCarouselAttachmentChange={onCarouselAttachmentChange}
/>
);
Expand Down
Loading