Skip to content

Commit

Permalink
feat: add optional props for dropdown option text
Browse files Browse the repository at this point in the history
- added `dropdownTextProps`, which can be used to add
  props to the text component that will be rendered, if the options
  for the dropdown were used without `renderRow`

#5
  • Loading branch information
donni106 committed Sep 18, 2020
1 parent 4ba101b commit 0216b2d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Prop | Type | Optional | Default | Description
`dropdownStyle` | object | Yes | | Style of the dropdown list.
`dropdownTextStyle` | object | Yes | | Style of the dropdown option text.
`dropdownTextHighlightStyle` | object | Yes | | Style of the dropdown selected option text.
`dropdownTextProps` | object | Yes | | Add custom props to the dropdown option text
`adjustFrame` | func | Yes | | This is a callback after the frame of the dropdown have been calculated and before showing. You will receive a style object as argument with some of the props like `width` `height` `top` `left` and `right`. Change them to appropriate values that accord with your requirement and **make the new style as the return value of this function**.
`renderRow` | func | Yes | | Customize render option rows: `function(option,index,isSelected)` **Will render a default row if `null`/`undefined`.**
`renderRowComponent`| Component | Yes | `TouchableOpacity` for iOS and `TouchableHighlight` for Android | Customize the touchable component of the rows
Expand Down
3 changes: 3 additions & 0 deletions components/ModalDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class ModalDropdown extends Component {
PropTypes.object,
PropTypes.array,
]),
dropdownTextProps: PropTypes.object,
adjustFrame: PropTypes.func,
renderRow: PropTypes.func,
renderRowComponent: PropTypes.oneOfType([
Expand Down Expand Up @@ -355,6 +356,7 @@ export default class ModalDropdown extends Component {
dropdownTextStyle,
dropdownTextHighlightStyle,
accessible,
dropdownTextProps,
} = this.props;
const RowTouchable = renderRowComponent;
const { selectedIndex } = this.state;
Expand All @@ -369,6 +371,7 @@ export default class ModalDropdown extends Component {
highlighted && styles.highlightedRowText,
highlighted && dropdownTextHighlightStyle,
]}
{...dropdownTextProps}
>
{item}
</Text>
Expand Down
2 changes: 2 additions & 0 deletions expo-example/ModalDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export default class ModalDropdown extends Component {
dropdownTextStyle,
dropdownTextHighlightStyle,
accessible,
dropdownTextProps,
} = this.props;
const RowTouchable = renderRowComponent;
const { selectedIndex } = this.state;
Expand All @@ -369,6 +370,7 @@ export default class ModalDropdown extends Component {
highlighted && styles.highlightedRowText,
highlighted && dropdownTextHighlightStyle,
]}
{...dropdownTextProps}
>
{item}
</Text>
Expand Down

0 comments on commit 0216b2d

Please sign in to comment.