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

feat: blur the composer focus when open context menu #47621

Merged
merged 14 commits into from
Oct 11, 2024
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
2 changes: 1 addition & 1 deletion src/libs/ReportActionComposeFocusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import navigationRef from './Navigation/navigationRef';
type FocusCallback = (shouldFocusForNonBlurInputOnTapOutside?: boolean) => void;

const composerRef: MutableRefObject<TextInput | null> = React.createRef<TextInput>();
const editComposerRef = React.createRef<TextInput>();
const editComposerRef: MutableRefObject<TextInput | null> = React.createRef<TextInput>();
// There are two types of composer: general composer (edit composer) and main composer.
// The general composer callback will take priority if it exists.
let focusCallback: FocusCallback | null = null;
Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Navigation from '@libs/Navigation/Navigation';
import Permissions from '@libs/Permissions';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import SelectionScraper from '@libs/SelectionScraper';
Expand Down Expand Up @@ -342,6 +343,8 @@ function ReportActionItem({
return;
}

ReportActionComposeFocusManager.composerRef.current?.blur();
ReportActionComposeFocusManager.editComposerRef.current?.blur();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of calling individual blur, can we define a utility function in ReportActionComposeFocusManager and call blur when focussed? I think that would be neater.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm let me check on this.

setIsContextMenuActive(true);
const selection = SelectionScraper.getCurrentSelection();
ReportActionContextMenu.showContextMenu(
Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/report/ReportActionItemMessageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ function ReportActionItemMessageEdit(
style={[styles.textInputCompose, styles.flex1, styles.bgTransparent]}
onFocus={() => {
setIsFocused(true);
if (textInputRef.current) {
ReportActionComposeFocusManager.editComposerRef.current = textInputRef.current;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let us reset the editComposerRef when the focus is lost to avoid dangling references. One way to do this is by resetting it inside ReportActionComposeFocusManager.clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we shouldn't reset editComposerRef since we use it to restore focus in case users open edit emoji picker then dismiss it

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I am missing something here but why would we need editComposerRef after ReportActionComposeFocusManager.clear is called here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, when ReportActionComposeFocusManager.clear we can reset editComposerRef, but not when the focus is lost. So you mean to reset it when the edit composer disappears (not when it's blurred), right?

Copy link
Contributor

Choose a reason for hiding this comment

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

when ReportActionComposeFocusManager.clear we can reset editComposerRef

Yes, that's what I meant

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please check if we also have to set the editComposerRef on component mount of ReportActionItemMessageEdit because I ran into issues where the edit composer did not blur as editComposerRef was not set at all? Here is a video that demonstrates this. Please have a look.

47621-mweb-safari-blurissue.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me check this and get back to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rojiphil after testing, there's a small change needed to fix this issue. As ReportActionComposeFocusManager.clear(); is triggered in both main and edit composer, when users open new edit composer, editComposerRef is set, then the logic clear

in main composer would reset editComposerRef

-> It’s wrong since the edit composer is still open

I think we should set/reset editComposerRef in ReportActionItemMessageEdit. I have pushed the latest commit with the change.

}
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
reportScrollManager.scrollToIndex(index, true);
Expand Down
Loading