-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Refactor picker to be a cross-platform component #2242
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3ede3ce
Add method docs
tgolen 54a0047
Rename checkbox callback prop
tgolen 037dc18
Finish renaming the callback prop
tgolen b88ba8b
Fix proptype warnings
tgolen 1c86bf7
Refactor picker into its own component
tgolen e4bdc92
DRY render logic
tgolen d571a87
Remove unused component
tgolen ff00697
Add more method docs
tgolen 0a1823c
Revert the DRY changes for checkbox
tgolen cd9618e
Merge branch 'master' into tgolen-improve-profile-quality
tgolen 5a62d87
Rename files to match conventions
tgolen dcd92bc
Merge branch 'master' into tgolen-improve-profile-quality
tgolen 6abfbb9
Only have platform specific styles
tgolen be475cd
Revert changes to lock file
tgolen d10d340
Merge branch 'master' into tgolen-improve-profile-quality
tgolen 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 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 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,43 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
const propTypes = { | ||
// A callback method that is called when the value changes and it received the selected value as an argument | ||
onChange: PropTypes.func.isRequired, | ||
|
||
// Whether or not to show the disabled styles | ||
useDisabledStyles: PropTypes.bool, | ||
|
||
// The items to display in the list of selections | ||
items: PropTypes.arrayOf(PropTypes.shape({ | ||
// The value of the item that is being selected | ||
value: PropTypes.string.isRequired, | ||
|
||
// The text to display for the item | ||
label: PropTypes.string.isRequired, | ||
})).isRequired, | ||
|
||
// Something to show as the placeholder before something is selected | ||
placeholder: PropTypes.shape({ | ||
// The value of the placeholder item, usually an empty string | ||
value: PropTypes.string, | ||
|
||
// The text to be displayed as the placeholder | ||
label: PropTypes.string, | ||
}), | ||
|
||
// The value that needs to be selected | ||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
|
||
// An icon to display with the picker | ||
icon: PropTypes.func.isRequired, | ||
}; | ||
const defaultProps = { | ||
useDisabledStyles: false, | ||
placeholder: {}, | ||
value: null, | ||
}; | ||
|
||
export { | ||
propTypes, | ||
defaultProps, | ||
}; |
This file contains 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,31 @@ | ||
import React from 'react'; | ||
import RNPickerSelect from 'react-native-picker-select'; | ||
|
||
import styles from '../../styles/styles'; | ||
import pickerDisabledStyles from './pickerDisabledStyles'; | ||
import * as pickerPropTypes from './PickerPropTypes'; | ||
|
||
const Picker = ({ | ||
onChange, | ||
items, | ||
useDisabledStyles, | ||
placeholder, | ||
value, | ||
icon, | ||
}) => ( | ||
<RNPickerSelect | ||
onValueChange={onChange} | ||
items={items} | ||
style={useDisabledStyles ? pickerDisabledStyles : styles.picker} | ||
useNativeAndroidPickerStyle={false} | ||
placeholder={placeholder} | ||
value={value} | ||
Icon={icon} | ||
/> | ||
); | ||
|
||
Picker.propTypes = pickerPropTypes.propTypes; | ||
Picker.defaultProps = pickerPropTypes.defaultProps; | ||
Picker.displayName = 'Picker'; | ||
|
||
export default Picker; |
This file contains 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,6 @@ | ||
import styles from '../../../styles/styles'; | ||
|
||
export default { | ||
...styles.picker, | ||
inputAndroid: [styles.picker.inputAndroid, styles.textInput, styles.disabledTextInput], | ||
}; |
This file contains 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,6 @@ | ||
import styles from '../../../styles/styles'; | ||
|
||
export default { | ||
...styles.picker, | ||
inputIOS: [styles.picker.inputIOS, styles.textInput, styles.disabledTextInput], | ||
}; |
This file contains 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,6 @@ | ||
import styles from '../../../styles/styles'; | ||
|
||
export default { | ||
...styles.picker, | ||
inputWeb: [styles.picker.inputWeb, styles.textInput, styles.disabledTextInput], | ||
}; |
This file contains 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 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 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 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
File renamed without changes.
This file contains 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
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.
why the switch to making these prop optional?
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.
There was a prop warning in the console that
undefined
was being passed. I looked through the code and there is a spot where the report action passed is{}
(an empty object) so I just corrected the propTypes here.