diff --git a/src/hooks/useRestoreInputFocus.ts b/src/hooks/useRestoreInputFocus.ts new file mode 100644 index 000000000000..a8049eb70b77 --- /dev/null +++ b/src/hooks/useRestoreInputFocus.ts @@ -0,0 +1,21 @@ +import {useEffect, useRef} from 'react'; +import {InteractionManager, Keyboard} from 'react-native'; +import {KeyboardController} from 'react-native-keyboard-controller'; + +const useRestoreInputFocus = (isLostFocus: boolean) => { + const keyboardVisibleBeforeLoosingFocusRef = useRef(false); + + useEffect(() => { + if (isLostFocus) { + keyboardVisibleBeforeLoosingFocusRef.current = Keyboard.isVisible(); + } + + if (!isLostFocus && keyboardVisibleBeforeLoosingFocusRef.current) { + InteractionManager.runAfterInteractions(() => { + KeyboardController.setFocusTo('current'); + }); + } + }, [isLostFocus]); +}; + +export default useRestoreInputFocus; diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 1d7deea43a04..b88a5a0bd33e 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -16,6 +16,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import usePaginatedReportActions from '@hooks/usePaginatedReportActions'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useRestoreInputFocus from '@hooks/useRestoreInputFocus'; import useStyleUtils from '@hooks/useStyleUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; @@ -268,6 +269,7 @@ function BaseReportActionContextMenu({ }, {isActive: shouldEnableArrowNavigation && shouldEnableContextMenuEnterShortcut, shouldPreventDefault: false}, ); + useRestoreInputFocus(isVisible); const openOverflowMenu = (event: GestureResponderEvent | MouseEvent, anchorRef: MutableRefObject) => { showContextMenu(