From 2bf777e96f3e5910e69d974fa8a352c49f947633 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 26 Mar 2024 15:52:52 +0300 Subject: [PATCH] fix auto focus for natives --- src/libs/ReportActionComposeFocusManager.ts | 6 +++--- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 2 +- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportActionComposeFocusManager.ts b/src/libs/ReportActionComposeFocusManager.ts index 64e4530e0fe5..7e387d807229 100644 --- a/src/libs/ReportActionComposeFocusManager.ts +++ b/src/libs/ReportActionComposeFocusManager.ts @@ -3,7 +3,7 @@ import type {TextInput} from 'react-native'; import ROUTES from '@src/ROUTES'; import Navigation from './Navigation/Navigation'; -type FocusCallback = () => void; +type FocusCallback = (shouldFocusForNative?: boolean) => void; const composerRef = React.createRef(); const editComposerRef = React.createRef(); @@ -29,7 +29,7 @@ function onComposerFocus(callback: FocusCallback | null, isMainComposer = false) /** * Request focus on the ReportActionComposer */ -function focus() { +function focus(shouldFocusForNative?: boolean) { /** Do not trigger the refocusing when the active route is not the report route, */ if (!Navigation.isActiveRoute(ROUTES.REPORT_WITH_ID.getRoute(Navigation.getTopmostReportId() ?? ''))) { return; @@ -40,7 +40,7 @@ function focus() { return; } - mainComposerFocusCallback(); + mainComposerFocusCallback(shouldFocusForNative); return; } diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index a270905256d6..d640b3cc6131 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -201,7 +201,7 @@ const ContextMenuActions: ContextMenuAction[] = [ if (closePopover) { hideContextMenu(false, () => { InteractionManager.runAfterInteractions(() => { - ReportActionComposeFocusManager.focus(); + ReportActionComposeFocusManager.focus(true); }); Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '0', reportAction, reportID); }); diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 2f9daa117273..d334d46eaa24 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -602,8 +602,8 @@ function ComposerWithSuggestions( const setUpComposeFocusManager = useCallback(() => { // This callback is used in the contextMenuActions to manage giving focus back to the compose input. - ReportActionComposeFocusManager.onComposerFocus(() => { - if (!willBlurTextInputOnTapOutside || !isFocused) { + ReportActionComposeFocusManager.onComposerFocus((shouldFocusForNative = false) => { + if ((!willBlurTextInputOnTapOutside && !shouldFocusForNative) || !isFocused) { return; }