-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor new date picker #21792
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
mountiny
merged 24 commits into
Expensify:main
from
ArekChr:callstack/refactor_new_date_picker
Jul 10, 2023
Merged
Refactor new date picker #21792
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
3db9586
refactor: remove navigation, fix props passing, remove unused functio…
ArekChr 1fab207
refactor: move CalendarPicker components to NewDatePicker dir
ArekChr cc26bc1
refactor: move ScreenSlideAnimation to separated file
ArekChr 9bd8759
refactor: move ScreenSlideAnimation to separated file
ArekChr dc1c96c
refactor: YearPickerPage constructor
ArekChr c65f5a1
fix: withlocalizeprops import
ArekChr a6a69de
refactor: remove old functionalities
ArekChr be2e0d0
fix: window animation jumping bug
ArekChr 8abedfd
refactor: undo imports order
ArekChr 0481fe3
refactor: mv default props to calendar picker
ArekChr ad29d05
fix: eslint-disable-next-line in useImperativeHandle and useEffect
ArekChr ab4ca50
refactor: remove Select Year from navigator
ArekChr ede1cdb
cr
ArekChr 4057bca
fix: cr
ArekChr 762cb47
fix: cr
ArekChr 58ce600
fix: typo
ArekChr 12088f7
chore: replace ScreenSlideAnimation for Modal
thiagobrez 1b4731f
chore: fix conflicts
thiagobrez 55f930d
chore: address YearPickerModal performance
thiagobrez cd3a520
chore: fix YearPickerModal propTypes
thiagobrez a050f8e
chore: fix tests
thiagobrez a457069
chore: move filtering to YearPickerModal
thiagobrez b85195e
test: fix unit tests
thiagobrez 0a1fad4
chore: prevent searching for non-num chars
thiagobrez 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
This file was deleted.
Oops, something went wrong.
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
10 changes: 5 additions & 5 deletions
10
src/components/CalendarPicker/ArrowIcon.js → ...NewDatePicker/CalendarPicker/ArrowIcon.js
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
85 changes: 85 additions & 0 deletions
85
src/components/NewDatePicker/CalendarPicker/YearPickerModal.js
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,85 @@ | ||
| import React, {useEffect, useMemo, useState} from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import _ from 'underscore'; | ||
| import HeaderWithBackButton from '../../HeaderWithBackButton'; | ||
| import CONST from '../../../CONST'; | ||
| import SelectionListRadio from '../../SelectionListRadio'; | ||
| import Modal from '../../Modal'; | ||
| import {radioListItemPropTypes} from '../../SelectionListRadio/selectionListRadioPropTypes'; | ||
| import useLocalize from '../../../hooks/useLocalize'; | ||
|
|
||
| const propTypes = { | ||
| /** Whether the modal is visible */ | ||
| isVisible: PropTypes.bool.isRequired, | ||
|
|
||
| /** The list of years to render */ | ||
| years: PropTypes.arrayOf(PropTypes.shape(radioListItemPropTypes)).isRequired, | ||
|
|
||
| /** Currently selected year */ | ||
| currentYear: PropTypes.number, | ||
|
|
||
| /** Function to call when the user selects a year */ | ||
| onYearChange: PropTypes.func, | ||
|
|
||
| /** Function to call when the user closes the year picker */ | ||
| onClose: PropTypes.func, | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| currentYear: new Date().getFullYear(), | ||
| onYearChange: () => {}, | ||
| onClose: () => {}, | ||
| }; | ||
|
|
||
| function YearPickerModal(props) { | ||
| const {translate} = useLocalize(); | ||
| const [searchText, setSearchText] = useState(''); | ||
| const {sections, headerMessage} = useMemo(() => { | ||
| const yearsList = searchText === '' ? props.years : _.filter(props.years, (year) => year.text.includes(searchText)); | ||
| return { | ||
| headerMessage: !yearsList.length ? translate('common.noResultsFound') : '', | ||
| sections: [{data: yearsList, indexOffset: 0}], | ||
| }; | ||
| }, [props.years, searchText, translate]); | ||
|
|
||
| useEffect(() => { | ||
| if (props.isVisible) { | ||
| return; | ||
| } | ||
| setSearchText(''); | ||
| }, [props.isVisible]); | ||
|
|
||
| return ( | ||
| <Modal | ||
| type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||
| isVisible={props.isVisible} | ||
| onClose={props.onClose} | ||
| onModalHide={props.onClose} | ||
| hideModalContentWhileAnimating | ||
|
mountiny marked this conversation as resolved.
|
||
| useNativeDriver | ||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('yearPickerPage.year')} | ||
| onBackButtonPress={props.onClose} | ||
| /> | ||
| <SelectionListRadio | ||
| shouldDelayFocus | ||
| textInputLabel={translate('yearPickerPage.selectYear')} | ||
| textInputValue={searchText} | ||
| textInputMaxLength={4} | ||
| onChangeText={(text) => setSearchText(text.replace(CONST.REGEX.NON_NUMERIC, '').trim())} | ||
| keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD} | ||
| headerMessage={headerMessage} | ||
| sections={sections} | ||
| onSelectRow={(option) => props.onYearChange(option.value)} | ||
| initiallyFocusedOptionKey={props.currentYear.toString()} | ||
| /> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| YearPickerModal.propTypes = propTypes; | ||
| YearPickerModal.defaultProps = defaultProps; | ||
| YearPickerModal.displayName = 'YearPickerModal'; | ||
|
|
||
| export default YearPickerModal; | ||
2 changes: 1 addition & 1 deletion
2
...nts/CalendarPicker/generateMonthMatrix.js → ...ker/CalendarPicker/generateMonthMatrix.js
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include
shouldHandleNavigationBackprops to handle physical back button on mWeb. More details in:#52383 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hungvu193
shouldHandleNavigationBackwas not present when this PR was implemented. It was added in #38693.