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 - mWeb auto focus on reply in thread #37929

Merged
merged 21 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
21 changes: 14 additions & 7 deletions src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,20 @@ function Composer(
disabled={isDisabled}
onKeyPress={handleKeyPress}
onFocus={(e) => {
ReportActionComposeFocusManager.onComposerFocus(() => {
if (!textInput.current) {
return;
}

textInput.current.focus();
});
if (isReportActionCompose) {
ReportActionComposeFocusManager.onComposerFocus(null);
} else {
// While a user was editing a comment and if they open on LHN menu we want the focus to return
// to the ReportActionItemMessageEdit compose after they click on the menu (for e.g. mark as read)
// so we assign the focus callback here.
ReportActionComposeFocusManager.onComposerFocus(() => {
if (!textInput.current) {
return;
}

textInput.current.focus();
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isReportActionCompose) {
ReportActionComposeFocusManager.onComposerFocus(null);
} else {
// While a user was editing a comment and if they open on LHN menu we want the focus to return
// to the ReportActionItemMessageEdit compose after they click on the menu (for e.g. mark as read)
// so we assign the focus callback here.
ReportActionComposeFocusManager.onComposerFocus(() => {
if (!textInput.current) {
return;
}
textInput.current.focus();
});
}
ReportActionComposeFocusManager.onComposerFocus(() => {
/*
While a user was editing a comment and if they open on LHN menu we want the focus to return
to the ReportActionItemMessageEdit compose after they click on the menu (for e.g. mark as read)
so we assign the focus callback here.
*/
if (!textInput.current || isReportActionCompose) {
return;
}
textInput.current.focus();
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. What we are trying to avoid for main composer is overriding of the focus callback; onComposerFocus is callback assigner so we should avoid overriding of mainComposerFocusCallback by focusCallback so when isReportActionCompose is true we reset it to null.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't get the reasoning behind this. Why can't we just return early in the callback if isReportActionCompose is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we want to achieve is when the focus is called from reply in thread we want to focus the compose in the newly created thread and we can do that via mainComposerFocusCallback set here

ReportActionComposeFocusManager.onComposerFocus((shouldFocusForNative = false) => {
if ((!willBlurTextInputOnTapOutside && !shouldFocusForNative) || !isFocused) {
return;
}
focus(false);
}, true);

But mainComposerFocusCallback are only called when focusCallback is not set.
if (typeof focusCallback !== 'function') {
if (typeof mainComposerFocusCallback !== 'function') {
return;
}
mainComposerFocusCallback(shouldFocusForNative);

So here what we want is to reset focusCallback to null so that our mainComposerFocusCallback will be called. But early returning, as U suggest, means we leave (without reseting) what was already set on focusCallback therefore our mainComposerFocusCallback will not be called.


props.onFocus?.(e);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionComposeFocusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let mainComposerFocusCallback: FocusCallback | null = null;
*
* @param callback callback to register
*/
function onComposerFocus(callback: FocusCallback, isMainComposer = false) {
function onComposerFocus(callback: FocusCallback | null, isMainComposer = false) {
if (isMainComposer) {
mainComposerFocusCallback = callback;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/libs/focusComposerWithDelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function focusComposerWithDelay(textInput: TextInput | null): FocusComposerWithD
return (shouldDelay = false) => {
// There could be other animations running while we trigger manual focus.
// This prevents focus from making those animations janky.

if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import type {MutableRefObject} from 'react';
import React from 'react';
import {InteractionManager} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent, Text, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -199,7 +200,9 @@ const ContextMenuActions: ContextMenuAction[] = [
onPress: (closePopover, {reportAction, reportID}) => {
if (closePopover) {
hideContextMenu(false, () => {
ReportActionComposeFocusManager.focus();
InteractionManager.runAfterInteractions(() => {
ReportActionComposeFocusManager.focus();
});
Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '0', reportAction, reportID);
});
return;
Expand Down
Loading