Skip to content

Commit

Permalink
fix auto focus for natives
Browse files Browse the repository at this point in the history
  • Loading branch information
FitseTLT committed Mar 26, 2024
1 parent 297cd03 commit 2bf777e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/libs/ReportActionComposeFocusManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextInput>();
const editComposerRef = React.createRef<TextInput>();
Expand All @@ -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;
Expand All @@ -40,7 +40,7 @@ function focus() {
return;
}

mainComposerFocusCallback();
mainComposerFocusCallback(shouldFocusForNative);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2bf777e

Please sign in to comment.