Repository navigation
New datepicker layout #85107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New datepicker layout #85107
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fdaf12b
new datepicker layout
mukhrr ffb2213
fixed month picker clamping issues
mukhrr fcaddf0
fixed start adn end month mapping
mukhrr 45ca048
fixed accessibility labels
mukhrr c761d61
Merge remote-tracking branch 'origin' into fix/83389
mukhrr 991548f
Fix CalendarPicker header layout to prevent text truncation
mukhrr fdd59bb
Reduce horizontal padding in CalendarPicker header from ph5 to ph3
mukhrr d0789ad
Add top padding to CalendarPicker container
mukhrr c742e58
Add translations for month/year navigation labels in calendar picker
mukhrr 0b7d884
Merge remote-tracking branch 'origin' into fix/83389
mukhrr 549ea1f
Add Spanish translations for date navigation labels
mukhrr f62edfe
Add Spanish translations for month picker labels
mukhrr 16b292b
Add tests for year transitions when navigating months in CalendarPicker
mukhrr d4d6653
Update src/components/DatePicker/CalendarPicker/MonthPickerModal.tsx
mukhrr 9378591
Update src/components/DatePicker/CalendarPicker/MonthPickerModal.tsx
mukhrr d094b4c
Extract month filtering logic to DateUtils.getFilteredMonthItems
mukhrr 59cfc0d
Wrap month and year picker buttons in View to fix flex layout
mukhrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/components/DatePicker/CalendarPicker/MonthPickerModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import React, {useEffect, useMemo, useState} from 'react'; | ||
| import {Keyboard} from 'react-native'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import Modal from '@components/Modal'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import SelectionList from '@components/SelectionList'; | ||
| import RadioListItem from '@components/SelectionList/ListItem/RadioListItem'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import DateUtils from '@libs/DateUtils'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| type MonthPickerModalProps = { | ||
| /** Whether the modal is visible */ | ||
| isVisible: boolean; | ||
|
|
||
| /** Currently selected month (0-indexed) */ | ||
| currentMonth?: number; | ||
|
|
||
| /** The year currently being viewed */ | ||
| currentYear?: number; | ||
|
|
||
| /** A minimum date (earliest) allowed to select */ | ||
| minDate?: Date; | ||
|
|
||
| /** A maximum date (latest) allowed to select */ | ||
| maxDate?: Date; | ||
|
|
||
| /** Function to call when the user selects a month */ | ||
| onMonthChange?: (month: number) => void; | ||
|
|
||
| /** Function to call when the user closes the month picker */ | ||
| onClose?: () => void; | ||
| }; | ||
|
|
||
| function MonthPickerModal({isVisible, currentMonth = new Date().getMonth(), currentYear = new Date().getFullYear(), minDate, maxDate, onMonthChange, onClose}: MonthPickerModalProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const [searchText, setSearchText] = useState(''); | ||
| const monthNames = DateUtils.getMonthNames(); | ||
|
|
||
| const allMonths = useMemo(() => DateUtils.getFilteredMonthItems(monthNames, currentYear, currentMonth, minDate, maxDate), [monthNames, currentMonth, currentYear, minDate, maxDate]); | ||
|
|
||
| const {data, headerMessage} = useMemo(() => { | ||
| const filteredMonths = searchText === '' ? allMonths : allMonths.filter((month) => month.text.toLowerCase().includes(searchText.toLowerCase())); | ||
| return { | ||
| headerMessage: !filteredMonths.length ? translate('common.noResultsFound') : '', | ||
| data: filteredMonths, | ||
| }; | ||
| }, [allMonths, searchText, translate]); | ||
|
|
||
| useEffect(() => { | ||
| if (isVisible) { | ||
| return; | ||
| } | ||
| setSearchText(''); | ||
| }, [isVisible]); | ||
|
|
||
| const textInputOptions = useMemo( | ||
| () => ({ | ||
| label: translate('monthPickerPage.selectMonth'), | ||
| value: searchText, | ||
| onChangeText: setSearchText, | ||
| headerMessage, | ||
| }), | ||
| [headerMessage, searchText, translate], | ||
| ); | ||
|
|
||
| return ( | ||
| <Modal | ||
| type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||
| isVisible={isVisible} | ||
| onClose={() => onClose?.()} | ||
| onModalHide={onClose} | ||
| shouldHandleNavigationBack | ||
| shouldUseCustomBackdrop | ||
| onBackdropPress={onClose} | ||
| enableEdgeToEdgeBottomSafeAreaPadding | ||
| > | ||
| <ScreenWrapper | ||
| style={[styles.pb0]} | ||
| includePaddingTop={false} | ||
| enableEdgeToEdgeBottomSafeAreaPadding | ||
| testID="MonthPickerModal" | ||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('monthPickerPage.month')} | ||
| onBackButtonPress={onClose} | ||
| /> | ||
| <SelectionList | ||
| data={data} | ||
| ListItem={RadioListItem} | ||
| onSelectRow={(option) => { | ||
| Keyboard.dismiss(); | ||
| onMonthChange?.(option.value); | ||
| }} | ||
| textInputOptions={textInputOptions} | ||
| initiallyFocusedItemKey={currentMonth.toString()} | ||
| disableMaintainingScrollPosition | ||
| addBottomSafeAreaPadding | ||
| shouldStopPropagation | ||
| showScrollIndicator | ||
| /> | ||
| </ScreenWrapper> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| export default MonthPickerModal; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.