From f368deff9b266de030eb0331e6ac29c29b0cd54d Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Wed, 5 Jun 2024 13:38:31 +0200 Subject: [PATCH] use shouldDelayFocus prop --- .../SelectionList/BaseSelectionList.tsx | 36 ++++++++++--------- src/pages/ChatFinderPage/index.tsx | 1 + 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index f3f7f56be44f..ca86c80eda1f 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -85,6 +85,7 @@ function BaseSelectionList( onEndReachedThreshold, windowSize = 5, updateCellsBatchingPeriod = 50, + shouldDelayFocus = true, }: BaseSelectionListProps, ref: ForwardedRef, ) { @@ -506,27 +507,28 @@ function BaseSelectionList( }; }, [debouncedSelectFocusedOption, shouldDebounceRowSelect]); + /** Function to focus text input */ + const focusTextInput = useCallback(() => { + if (!innerTextInputRef.current) { + return; + } + + innerTextInputRef.current.focus(); + }, []); + /** Focuses the text input when the component comes into focus and after any navigation animations finish. */ useFocusEffect( useCallback(() => { - if (!textInputAutoFocus) { - return; - } - if (shouldShowTextInput) { - focusTimeoutRef.current = setTimeout(() => { - if (!innerTextInputRef.current) { - return; - } - innerTextInputRef.current.focus(); - }, CONST.ANIMATED_TRANSITION); - } - return () => { - if (!focusTimeoutRef.current) { - return; + if (textInputAutoFocus && shouldShowTextInput) { + if (shouldDelayFocus) { + focusTimeoutRef.current = setTimeout(focusTextInput, CONST.ANIMATED_TRANSITION); + } else { + focusTextInput(); } - clearTimeout(focusTimeoutRef.current); - }; - }, [shouldShowTextInput, textInputAutoFocus]), + } + + return () => focusTimeoutRef.current && clearTimeout(focusTimeoutRef.current); + }, [shouldShowTextInput, textInputAutoFocus, shouldDelayFocus, focusTextInput]), ); const prevTextInputValue = usePrevious(textInputValue); diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index 3af7dd506a4f..252f98c76611 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -193,6 +193,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa showLoadingPlaceholder={!areOptionsInitialized || !isScreenTransitionEnd} footerContent={!isDismissed && ChatFinderPageFooterInstance} isLoadingNewOptions={!!isSearchingForReports} + shouldDelayFocus={false} /> );