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
1 change: 0 additions & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ const CONST = {
POPOVER_DROPDOWN_MAX_HEIGHT: 416,
POPOVER_MENU_MAX_HEIGHT: 496,
POPOVER_MENU_MAX_HEIGHT_MOBILE: 432,
MOVE_SELECTED_ITEMS_TO_TOP_OF_LIST_THRESHOLD: 8,
POPOVER_DATE_WIDTH: 338,
POPOVER_DATE_RANGE_WIDTH: 672,
POPOVER_DATE_MAX_HEIGHT: 366,
Expand Down
12 changes: 3 additions & 9 deletions src/components/CountryPicker/CountrySelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import useDebouncedState from '@hooks/useDebouncedState';
import useInitialSelection from '@hooks/useInitialSelection';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import searchOptions from '@libs/searchOptions';
import type {Option} from '@libs/searchOptions';
import {moveInitialSelectionToTopByValue} from '@libs/SelectionListOrderUtils';
import StringUtils from '@libs/StringUtils';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -38,9 +36,6 @@ type CountrySelectorModalProps = {
function CountrySelectorModal({isVisible, currentCountry, onCountrySelected, onClose, label, onBackdropPress}: CountrySelectorModalProps) {
const {translate} = useLocalize();
const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const initialSelectedValue = useInitialSelection(currentCountry || undefined, {resetDeps: [isVisible]});
const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : [];
const initiallyFocusedCountry = initialSelectedValue;

const countries = useMemo(
() =>
Expand All @@ -56,8 +51,8 @@ function CountrySelectorModal({isVisible, currentCountry, onCountrySelected, onC
}),
[translate, currentCountry],
);
const orderedCountries = moveInitialSelectionToTopByValue(countries, initialSelectedValues);
const searchResults = searchOptions(debouncedSearchValue, debouncedSearchValue ? countries : orderedCountries);

const searchResults = searchOptions(debouncedSearchValue, countries);
const headerMessage = debouncedSearchValue.trim() && !searchResults.length ? translate('common.noResultsFound') : '';

const styles = useThemeStyles();
Expand Down Expand Up @@ -94,10 +89,9 @@ function CountrySelectorModal({isVisible, currentCountry, onCountrySelected, onC
<SelectionList
data={searchResults}
textInputOptions={textInputOptions}
searchValueForFocusSync={debouncedSearchValue}
onSelectRow={onCountrySelected}
ListItem={RadioListItem}
initiallyFocusedItemKey={initiallyFocusedCountry}
initiallyFocusedItemKey={currentCountry}
shouldSingleExecuteRowSelect
shouldStopPropagation
/>
Expand Down
12 changes: 2 additions & 10 deletions src/components/PushRowWithModal/PushRowModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import useDebouncedState from '@hooks/useDebouncedState';
import useInitialSelection from '@hooks/useInitialSelection';
import useLocalize from '@hooks/useLocalize';
import searchOptions from '@libs/searchOptions';
import {moveInitialSelectionToTopByValue} from '@libs/SelectionListOrderUtils';
import StringUtils from '@libs/StringUtils';
import CONST from '@src/CONST';

Expand Down Expand Up @@ -46,9 +44,6 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
const {translate} = useLocalize();

const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const initialSelectedValue = useInitialSelection(selectedOption || undefined, {resetDeps: [isVisible]});
const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : [];
const initiallyFocusedOption = initialSelectedValue;

const options = useMemo(
() =>
Expand All @@ -62,8 +57,6 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
[optionsList, selectedOption],
);

const orderedOptions = moveInitialSelectionToTopByValue(options, initialSelectedValues);

const handleSelectRow = (option: ListItemType) => {
onOptionChange(option.value);
onClose();
Expand All @@ -74,7 +67,7 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
setSearchValue('');
};

const searchResults = searchOptions(debouncedSearchValue, debouncedSearchValue ? options : orderedOptions);
const searchResults = searchOptions(debouncedSearchValue, options);

const textInputOptions = useMemo(
() => ({
Expand Down Expand Up @@ -109,8 +102,7 @@ function PushRowModal({isVisible, selectedOption, onOptionChange, onClose, optio
ListItem={RadioListItem}
onSelectRow={handleSelectRow}
textInputOptions={textInputOptions}
searchValueForFocusSync={debouncedSearchValue}
initiallyFocusedItemKey={initiallyFocusedOption}
initiallyFocusedItemKey={selectedOption}
disableMaintainingScrollPosition
shouldShowTooltips={false}
showScrollIndicator
Expand Down
6 changes: 2 additions & 4 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function BaseSelectionList<TItem extends ListItem>({
ref,
ListItem,
textInputOptions,
searchValueForFocusSync,
initiallyFocusedItemKey,
onSelectRow,
onSelectAll,
Expand Down Expand Up @@ -206,7 +205,6 @@ function BaseSelectionList<TItem extends ListItem>({
// Including data.length ensures FlashList resets its layout cache when the list size changes
// This prevents "index out of bounds" errors when filtering reduces the list size
const extraData = useMemo(() => [data.length], [data.length]);
const syncedSearchValue = searchValueForFocusSync ?? textInputOptions?.value;

const selectRow = useCallback(
(item: TItem, indexToFocus?: number) => {
Expand Down Expand Up @@ -496,12 +494,12 @@ function BaseSelectionList<TItem extends ListItem>({
initiallyFocusedItemKey,
isItemSelected,
focusedIndex,
searchValue: syncedSearchValue,
searchValue: textInputOptions?.value,
setFocusedIndex,
});

useSearchFocusSync({
searchValue: syncedSearchValue,
searchValue: textInputOptions?.value,
data,
selectedOptionsCount: dataDetails.selectedOptions.length,
isItemSelected,
Expand Down
3 changes: 0 additions & 3 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ type BaseSelectionListProps<TItem extends ListItem> = {
/** Configuration options for the text input */
textInputOptions?: TextInputOptions;

/** Search value used for focus synchronization. Defaults to textInputOptions.value */
searchValueForFocusSync?: string;

/** Whether to show the text input */
shouldShowTextInput?: boolean;

Expand Down
11 changes: 2 additions & 9 deletions src/components/StatePicker/StateSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import useDebouncedState from '@hooks/useDebouncedState';
import useInitialSelection from '@hooks/useInitialSelection';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import searchOptions from '@libs/searchOptions';
import type {Option} from '@libs/searchOptions';
import {moveInitialSelectionToTopByValue} from '@libs/SelectionListOrderUtils';
import StringUtils from '@libs/StringUtils';
import CONST from '@src/CONST';

Expand Down Expand Up @@ -41,9 +39,6 @@ function StateSelectorModal({isVisible, currentState, onStateSelected, onClose,
const {translate} = useLocalize();
const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const styles = useThemeStyles();
const initialSelectedValue = useInitialSelection(currentState || undefined, {resetDeps: [isVisible]});
const initialSelectedValues = initialSelectedValue ? [initialSelectedValue] : [];
const initiallyFocusedState = initialSelectedValue;

const countryStates = useMemo(
() =>
Expand All @@ -62,8 +57,7 @@ function StateSelectorModal({isVisible, currentState, onStateSelected, onClose,
[translate, currentState],
);

const orderedCountryStates = moveInitialSelectionToTopByValue(countryStates, initialSelectedValues);
const searchResults = searchOptions(debouncedSearchValue, debouncedSearchValue ? countryStates : orderedCountryStates);
const searchResults = searchOptions(debouncedSearchValue, countryStates);

const textInputOptions = useMemo(
() => ({
Expand Down Expand Up @@ -99,8 +93,7 @@ function StateSelectorModal({isVisible, currentState, onStateSelected, onClose,
ListItem={RadioListItem}
onSelectRow={onStateSelected}
textInputOptions={textInputOptions}
searchValueForFocusSync={debouncedSearchValue}
initiallyFocusedItemKey={initiallyFocusedState}
initiallyFocusedItemKey={currentState}
disableMaintainingScrollPosition
shouldSingleExecuteRowSelect
shouldStopPropagation
Expand Down
21 changes: 6 additions & 15 deletions src/components/ValuePicker/ValueSelectionList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, {useMemo} from 'react';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import useInitialSelection from '@hooks/useInitialSelection';
import {moveInitialSelectionToTopByValue} from '@libs/SelectionListOrderUtils';
import type {ValueSelectionListProps} from './types';

function ValueSelectionList({
Expand All @@ -13,27 +11,20 @@ function ValueSelectionList({
addBottomSafeAreaPadding = true,
disableKeyboardShortcuts = false,
alternateNumberOfSupportedLines,
isVisible,
}: ValueSelectionListProps) {
const initialSelectedValue = useInitialSelection(selectedItem?.value ? selectedItem.value : undefined, isVisible === undefined ? {resetOnFocus: true} : {resetDeps: [isVisible]});
const initiallyFocusedItemKey = initialSelectedValue;

const options = useMemo(() => {
const mappedOptions = items.map((item) => ({value: item.value ?? '', alternateText: item.description, text: item.label ?? '', keyForList: item.value ?? ''}));
const orderedOptions = moveInitialSelectionToTopByValue(mappedOptions, initialSelectedValue ? [initialSelectedValue] : []);

return orderedOptions.map((item) => ({...item, isSelected: item.value === selectedItem?.value}));
}, [initialSelectedValue, items, selectedItem?.value]);
const options = useMemo(
() => items.map((item) => ({value: item.value, alternateText: item.description, text: item.label ?? '', isSelected: item === selectedItem, keyForList: item.value ?? ''})),
[items, selectedItem],
);

return (
<SelectionList
data={options}
onSelectRow={(item) => onItemSelected?.(item)}
initiallyFocusedItemKey={initiallyFocusedItemKey}
initiallyFocusedItemKey={selectedItem?.value}
shouldStopPropagation
shouldShowTooltips={shouldShowTooltips}
shouldScrollToFocusedIndex={false}
shouldScrollToFocusedIndexOnMount={false}
shouldUpdateFocusedIndex
ListItem={RadioListItem}
addBottomSafeAreaPadding={addBottomSafeAreaPadding}
disableKeyboardShortcuts={disableKeyboardShortcuts}
Expand Down
1 change: 0 additions & 1 deletion src/components/ValuePicker/ValueSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function ValueSelectorModal({
<ValueSelectionList
items={items}
selectedItem={selectedItem}
isVisible={isVisible}
onItemSelected={onItemSelected}
shouldShowTooltips={shouldShowTooltips}
disableKeyboardShortcuts={disableKeyboardShortcuts}
Expand Down
5 changes: 1 addition & 4 deletions src/components/ValuePicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ type ValueSelectorModalProps = {
type ValueSelectionListProps = Pick<
ValueSelectorModalProps,
'items' | 'selectedItem' | 'onItemSelected' | 'shouldShowTooltips' | 'addBottomSafeAreaPadding' | 'disableKeyboardShortcuts' | 'alternateNumberOfSupportedLines'
> & {
/** Whether the parent modal is visible */
isVisible?: boolean;
};
>;

type ValuePickerProps = ForwardedFSClassProps & {
/** Item to display */
Expand Down
50 changes: 0 additions & 50 deletions src/hooks/useInitialSelection.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/libs/SelectionListOrderUtils.ts

This file was deleted.

Loading
Loading