Skip to content

Commit 0e6dba4

Browse files
authored
Merge pull request #37929 from FitseTLT/fix-auto-focus-on-reply-in-thread
Fix - mWeb auto focus on reply in thread
2 parents ddb83f2 + 6fd4517 commit 0e6dba4

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/components/Composer/index.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,20 @@ function Composer(
388388
disabled={isDisabled}
389389
onKeyPress={handleKeyPress}
390390
onFocus={(e) => {
391-
ReportActionComposeFocusManager.onComposerFocus(() => {
392-
if (!textInput.current) {
393-
return;
394-
}
395-
396-
textInput.current.focus();
397-
});
391+
if (isReportActionCompose) {
392+
ReportActionComposeFocusManager.onComposerFocus(null);
393+
} else {
394+
// While a user edits a comment, if they open the LHN menu, we want to ensure that
395+
// the focus returns to the message edit composer after they click on a menu item (e.g. mark as read).
396+
// To achieve this, we re-assign the focus callback here.
397+
ReportActionComposeFocusManager.onComposerFocus(() => {
398+
if (!textInput.current) {
399+
return;
400+
}
401+
402+
textInput.current.focus();
403+
});
404+
}
398405

399406
props.onFocus?.(e);
400407
}}

src/libs/ReportActionComposeFocusManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {TextInput} from 'react-native';
33
import ROUTES from '@src/ROUTES';
44
import Navigation from './Navigation/Navigation';
55

6-
type FocusCallback = () => void;
6+
type FocusCallback = (shouldFocusForNonBlurInputOnTapOutside?: boolean) => void;
77

88
const composerRef = React.createRef<TextInput>();
99
const editComposerRef = React.createRef<TextInput>();
@@ -18,7 +18,7 @@ let mainComposerFocusCallback: FocusCallback | null = null;
1818
*
1919
* @param callback callback to register
2020
*/
21-
function onComposerFocus(callback: FocusCallback, isMainComposer = false) {
21+
function onComposerFocus(callback: FocusCallback | null, isMainComposer = false) {
2222
if (isMainComposer) {
2323
mainComposerFocusCallback = callback;
2424
} else {
@@ -29,7 +29,7 @@ function onComposerFocus(callback: FocusCallback, isMainComposer = false) {
2929
/**
3030
* Request focus on the ReportActionComposer
3131
*/
32-
function focus() {
32+
function focus(shouldFocusForNonBlurInputOnTapOutside?: boolean) {
3333
/** Do not trigger the refocusing when the active route is not the report route, */
3434
if (!Navigation.isActiveRoute(ROUTES.REPORT_WITH_ID.getRoute(Navigation.getTopmostReportId() ?? ''))) {
3535
return;
@@ -40,7 +40,7 @@ function focus() {
4040
return;
4141
}
4242

43-
mainComposerFocusCallback();
43+
mainComposerFocusCallback(shouldFocusForNonBlurInputOnTapOutside);
4444
return;
4545
}
4646

src/pages/home/report/ContextMenu/ContextMenuActions.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
22
import type {MutableRefObject} from 'react';
33
import React from 'react';
4+
import {InteractionManager} from 'react-native';
45
// eslint-disable-next-line no-restricted-imports
56
import type {GestureResponderEvent, Text, View} from 'react-native';
67
import type {OnyxEntry} from 'react-native-onyx';
@@ -200,7 +201,11 @@ const ContextMenuActions: ContextMenuAction[] = [
200201
onPress: (closePopover, {reportAction, reportID}) => {
201202
if (closePopover) {
202203
hideContextMenu(false, () => {
203-
ReportActionComposeFocusManager.focus();
204+
InteractionManager.runAfterInteractions(() => {
205+
// Normally the focus callback of the main composer doesn't focus when willBlurTextInputOnTapOutside
206+
// is false, so we need to pass true here to override this condition.
207+
ReportActionComposeFocusManager.focus(true);
208+
});
204209
Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '0', reportAction, reportID);
205210
});
206211
return;

src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ function ComposerWithSuggestions(
591591

592592
const setUpComposeFocusManager = useCallback(() => {
593593
// This callback is used in the contextMenuActions to manage giving focus back to the compose input.
594-
ReportActionComposeFocusManager.onComposerFocus(() => {
595-
if (!willBlurTextInputOnTapOutside || !isFocused) {
594+
ReportActionComposeFocusManager.onComposerFocus((shouldFocusForNonBlurInputOnTapOutside = false) => {
595+
if ((!willBlurTextInputOnTapOutside && !shouldFocusForNonBlurInputOnTapOutside) || !isFocused) {
596596
return;
597597
}
598598

0 commit comments

Comments
 (0)