-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TS migration] Migrate 'Picker' and 'LocalePicker' components to TypeScript #30646
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
deetergp
merged 27 commits into
Expensify:main
from
VickyStash:ts-migration/picker-component
Dec 6, 2023
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2997f68
[TS migration] Migrate 'Picker' and 'LocalePicker' components
VickyStash 25f87b6
Update picker style type
VickyStash 80816b6
Update TODO messages
VickyStash 4a1773e
Update react-native-picker-select lib version to resolve ts issues
VickyStash 192998e
Merge branch 'main' into ts-migration/picker-component
VickyStash a8b8188
Update react-native-picker-select lib to fix TS issues
VickyStash 2cd2771
Merge branch 'main' into ts-migration/picker-component
VickyStash e376918
Update forwardRef logic
VickyStash 977058f
Merge branch 'main' into ts-migration/picker-component
VickyStash dbc9fca
Merge branch 'main' into ts-migration/picker-component
VickyStash f17b26e
Updates after merging main
VickyStash 548c98a
Trigger snyk checks
VickyStash 2222de7
Merge branch 'main' into ts-migration/picker-component
VickyStash a73ba69
Replace withLocalize HOC with hook usage
VickyStash da35fc0
Update picker props type to be generic
VickyStash aac29da
Create separate function for default picker icon
VickyStash a53ec87
Create separate Locale type and add useScroll hook
VickyStash 8914066
Rename custom hook
VickyStash e9b526c
Minor code improvements
VickyStash b6edfdc
Update key usage
VickyStash 3ce21d3
Merge branch 'main' into ts-migration/picker-component
VickyStash c1df876
Minor code improvements
VickyStash 9e3c8f7
Merge branch 'main' into ts-migration/picker-component
VickyStash 275a908
Updates after merging main
VickyStash eb53666
Remove old BasePicker js file
VickyStash 01ea064
Merge branch 'main' into ts-migration/picker-component
VickyStash 237bb94
Update hooks call order to follow main updates
VickyStash 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import React from 'react'; | ||
| import {OnyxEntry, withOnyx} from 'react-native-onyx'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useTheme from '@styles/themes/useTheme'; | ||
| import useThemeStyles from '@styles/useThemeStyles'; | ||
| import * as App from '@userActions/App'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Locale} from '@src/types/onyx'; | ||
| import Picker from './Picker'; | ||
| import type {PickerSize} from './Picker/types'; | ||
|
|
||
| type LocalePickerOnyxProps = { | ||
| /** Indicates which locale the user currently has selected */ | ||
| preferredLocale: OnyxEntry<Locale>; | ||
| }; | ||
|
|
||
| type LocalePickerProps = LocalePickerOnyxProps & { | ||
| /** Indicates size of a picker component and whether to render the label or not */ | ||
| size?: PickerSize; | ||
| }; | ||
|
|
||
| function LocalePicker({preferredLocale = CONST.LOCALES.DEFAULT, size = 'normal'}: LocalePickerProps) { | ||
| const theme = useTheme(); | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const localesToLanguages = CONST.LANGUAGES.map((language) => ({ | ||
| value: language, | ||
| label: translate(`languagePage.languages.${language}.label`), | ||
|
VickyStash marked this conversation as resolved.
|
||
| keyForList: language, | ||
| isSelected: preferredLocale === language, | ||
| })); | ||
|
|
||
| return ( | ||
| <Picker | ||
| label={size === 'normal' ? translate('languagePage.language') : null} | ||
| onInputChange={(locale) => { | ||
| if (locale === preferredLocale) { | ||
| return; | ||
| } | ||
|
|
||
| App.setLocale(locale); | ||
| }} | ||
| items={localesToLanguages} | ||
| size={size} | ||
| value={preferredLocale} | ||
| containerStyles={size === 'small' ? styles.pickerContainerSmall : {}} | ||
| backgroundColor={theme.signInPage} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| LocalePicker.displayName = 'LocalePicker'; | ||
|
|
||
| export default withOnyx<LocalePickerProps, LocalePickerOnyxProps>({ | ||
| preferredLocale: { | ||
| key: ONYXKEYS.NVP_PREFERRED_LOCALE, | ||
| }, | ||
| })(LocalePicker); | ||
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.
Picker needs to be fully tested as this change includes Expensify/react-native-picker-select#14 which has lots of upstream changes