Skip to content

Commit 5d9dc6f

Browse files
authored
Merge pull request Expensify#76150 from software-mansion-labs/@zfurtak/migrate-YearPickerModal
Make `YearPickerModal` use new `SelectionList`
2 parents 9ff3341 + 3ccae18 commit 5d9dc6f

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/components/DatePicker/CalendarPicker/YearPickerModal.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {Keyboard} from 'react-native';
33
import HeaderWithBackButton from '@components/HeaderWithBackButton';
44
import Modal from '@components/Modal';
55
import ScreenWrapper from '@components/ScreenWrapper';
6-
import SelectionList from '@components/SelectionListWithSections';
7-
import RadioListItem from '@components/SelectionListWithSections/RadioListItem';
6+
import SelectionList from '@components/SelectionList';
7+
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
88
import useLocalize from '@hooks/useLocalize';
99
import useThemeStyles from '@hooks/useThemeStyles';
1010
import CONST from '@src/CONST';
@@ -31,11 +31,11 @@ function YearPickerModal({isVisible, years, currentYear = new Date().getFullYear
3131
const styles = useThemeStyles();
3232
const {translate} = useLocalize();
3333
const [searchText, setSearchText] = useState('');
34-
const {sections, headerMessage} = useMemo(() => {
34+
const {data, headerMessage} = useMemo(() => {
3535
const yearsList = searchText === '' ? years : years.filter((year) => year.text?.includes(searchText));
3636
return {
3737
headerMessage: !yearsList.length ? translate('common.noResultsFound') : '',
38-
sections: [{data: yearsList.sort((a, b) => b.value - a.value), indexOffset: 0}],
38+
data: yearsList.sort((a, b) => b.value - a.value),
3939
};
4040
}, [years, searchText, translate]);
4141

@@ -46,6 +46,18 @@ function YearPickerModal({isVisible, years, currentYear = new Date().getFullYear
4646
setSearchText('');
4747
}, [isVisible]);
4848

49+
const textInputOptions = useMemo(
50+
() => ({
51+
label: translate('yearPickerPage.selectYear'),
52+
value: searchText,
53+
onChangeText: (text: string) => setSearchText(text.replaceAll(CONST.REGEX.NON_NUMERIC, '').trim()),
54+
headerMessage,
55+
maxLength: 4,
56+
inputMode: CONST.INPUT_MODE.NUMERIC,
57+
}),
58+
[headerMessage, searchText, translate],
59+
);
60+
4961
return (
5062
<Modal
5163
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
@@ -68,23 +80,18 @@ function YearPickerModal({isVisible, years, currentYear = new Date().getFullYear
6880
onBackButtonPress={onClose}
6981
/>
7082
<SelectionList
71-
textInputLabel={translate('yearPickerPage.selectYear')}
72-
textInputValue={searchText}
73-
textInputMaxLength={4}
74-
onChangeText={(text) => setSearchText(text.replaceAll(CONST.REGEX.NON_NUMERIC, '').trim())}
75-
inputMode={CONST.INPUT_MODE.NUMERIC}
76-
headerMessage={headerMessage}
77-
sections={sections}
83+
data={data}
84+
ListItem={RadioListItem}
7885
onSelectRow={(option) => {
7986
Keyboard.dismiss();
8087
onYearChange?.(option.value);
8188
}}
82-
initiallyFocusedOptionKey={currentYear.toString()}
83-
showScrollIndicator
84-
shouldStopPropagation
85-
shouldUseDynamicMaxToRenderPerBatch
86-
ListItem={RadioListItem}
89+
textInputOptions={textInputOptions}
90+
initiallyFocusedItemKey={currentYear.toString()}
91+
disableMaintainingScrollPosition
8792
addBottomSafeAreaPadding
93+
shouldStopPropagation
94+
showScrollIndicator
8895
/>
8996
</ScreenWrapper>
9097
</Modal>

src/components/DatePicker/CalendarPicker/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {ListItem} from '@components/SelectionListWithSections/types';
1+
import type {ListItem} from '@components/SelectionList/types';
22

33
type CalendarPickerListItem = ListItem & {
44
/** The value representing a year in the CalendarPicker */

0 commit comments

Comments
 (0)