Skip to content

Commit

Permalink
Merge pull request #43099 from software-mansion-labs/filip-solecki/re…
Browse files Browse the repository at this point in the history
…move-selection-list-focus-delay

Fix Slow Chat Switcher issue
  • Loading branch information
mountiny authored Jun 12, 2024
2 parents 05f85cb + 35139ea commit 4d8d46c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function BaseSelectionList<TItem extends ListItem>(
windowSize = 5,
updateCellsBatchingPeriod = 50,
removeClippedSubviews = true,
shouldDelayFocus = true,
}: BaseSelectionListProps<TItem>,
ref: ForwardedRef<SelectionListHandle>,
) {
Expand Down Expand Up @@ -507,27 +508,28 @@ function BaseSelectionList<TItem extends ListItem>(
};
}, [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);
Expand Down
1 change: 1 addition & 0 deletions src/pages/ChatFinderPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
showLoadingPlaceholder={!areOptionsInitialized || !isScreenTransitionEnd}
footerContent={!isDismissed && ChatFinderPageFooterInstance}
isLoadingNewOptions={!!isSearchingForReports}
shouldDelayFocus={false}
/>
</ScreenWrapper>
);
Expand Down

0 comments on commit 4d8d46c

Please sign in to comment.