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 1 commit
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
1 change: 0 additions & 1 deletion src/libs/ReportActionComposeFocusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function focus(shouldFocusForNonBlurInputOnTapOutside?: boolean) {
* Clear the registered focus callback
*/
function clear(isPriorityCallback = false) {
editComposerRef.current = null;
if (isPriorityCallback) {
priorityFocusCallback = null;
} else {
Expand Down
17 changes: 14 additions & 3 deletions src/pages/home/report/ReportActionItemMessageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ function ReportActionItemMessageEdit(
};
}, []);

useEffect(
// Remove focus callback on unmount to avoid stale callbacks
() => {
if (textInputRef.current) {
ReportActionComposeFocusManager.editComposerRef.current = textInputRef.current;
}
return () => {
ReportActionComposeFocusManager.editComposerRef.current = null;
Copy link
Contributor

@rojiphil rojiphil Sep 30, 2024

Choose a reason for hiding this comment

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

As mentioned here already, we just had to reset the editComposerRef when isPriorityCallback is true because we call clear(true) in ReportActionItemMessageEdit here. Can we move the code to reset the editComposerRef to within 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.

Yes, we can. I'll update soon

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 I updated

ReportActionComposeFocusManager.clear(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. There is already a code used for handling unmount as mentioned here. Let us use that code to avoid duplicate coding.
  2. Also, shouldn't it be ReportActionComposeFocusManager.clear(); here as we do not want to reset the editcomposer if focus already exists on another edit item. Here is a test video demonstrating the problem:
47621-clear-issue-1.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.

Here's the result after refactoring

Screen.Recording.2024-10-01.at.11.21.52.mov

};
},
[],
);

// We consider the report action active if it's focused, its emoji picker is open or its context menu is open
const isActive = useCallback(
() => isFocusedRef.current || EmojiPickerAction.isActive(action.reportActionID) || ReportActionContextMenu.isActiveReportAction(action.reportActionID),
Expand Down Expand Up @@ -516,9 +530,6 @@ 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.

I am not sure why we removed this as I think we need to set the editComposerRef here too i.e. when the edit composer receives focus as there will be cases where the edit composer is mounted but the focus has changed. Here is a test video demonstrating the problem

47621-focus-issue-1.mp4

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