Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {SearchQueryItem} from '@components/SelectionListWithSections/Search
import {isSearchQueryItem} from '@components/SelectionListWithSections/Search/SearchQueryListItem';
import type {SelectionListHandle} from '@components/SelectionListWithSections/types';
import useDebouncedState from '@hooks/useDebouncedState';
import useFocusAfterNav from '@hooks/useFocusAfterNav';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -474,6 +475,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
});

const modalWidth = shouldUseNarrowLayout ? styles.w100 : {width: variables.searchRouterPopoverWidth};
const autoFocus = useFocusAfterNav(textInputRef);

return (
<View
Expand Down Expand Up @@ -512,6 +514,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
selection={selection}
substitutionMap={autocompleteSubstitutions}
ref={textInputRef}
autoFocus={autoFocus}
/>
</View>
{shouldShowList && (
Expand Down
18 changes: 18 additions & 0 deletions src/hooks/useFocusAfterNav/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {useFocusEffect} from '@react-navigation/native';
import CONST from '@src/CONST';
import type UseFocusAfterNav from './type';

/** We added a delay to focus on text input to allow navigation/modal animations to get completed,
see issue https://github.com/Expensify/App/issues/65855 for more details */
const useFocusAfterNav: UseFocusAfterNav = (ref) => {
useFocusEffect(() => {
const timeoutId = setTimeout(() => {
ref.current?.focus();
}, CONST.ANIMATED_TRANSITION);

return () => clearTimeout(timeoutId);
});
return false;
};

export default useFocusAfterNav;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

import {useFocusEffect} from '@react-navigation/native';
import {RefObject} from 'react';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import CONST from '@src/CONST';

const useFocusAfterNav = (ref: RefObject<AnimatedTextInputRef | null>) => {
    useFocusEffect(() => {
        const timeoutId = setTimeout(() => {
            ref.current?.focus();
        }, CONST.ANIMATED_TRANSITION);

        return () => clearTimeout(timeoutId);
    });
};

export default useFocusAfterNav;

isn't the above a clean way to write things ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it is! updated.

7 changes: 7 additions & 0 deletions src/hooks/useFocusAfterNav/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type UseFocusAfterNav from './type';

const useFocusAfterNav: UseFocusAfterNav = () => {
return true;
};

export default useFocusAfterNav;
6 changes: 6 additions & 0 deletions src/hooks/useFocusAfterNav/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {RefObject} from 'react';
import type {AnimatedTextInputRef} from '@components/RNTextInput';

type UseFocusAfterNav = (ref: RefObject<AnimatedTextInputRef | null>) => boolean;

export default UseFocusAfterNav;
Loading