From 0216b2d2b198b993ad3296514adbbef88a3d9b3b Mon Sep 17 00:00:00 2001 From: Daniel Molnar Date: Fri, 18 Sep 2020 10:22:29 +0200 Subject: [PATCH] feat: add optional props for dropdown option text - 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 --- README.md | 1 + components/ModalDropdown.js | 3 +++ expo-example/ModalDropdown.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 2537499..a43f6f8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/components/ModalDropdown.js b/components/ModalDropdown.js index cf092b3..7cc90d8 100644 --- a/components/ModalDropdown.js +++ b/components/ModalDropdown.js @@ -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([ @@ -355,6 +356,7 @@ export default class ModalDropdown extends Component { dropdownTextStyle, dropdownTextHighlightStyle, accessible, + dropdownTextProps, } = this.props; const RowTouchable = renderRowComponent; const { selectedIndex } = this.state; @@ -369,6 +371,7 @@ export default class ModalDropdown extends Component { highlighted && styles.highlightedRowText, highlighted && dropdownTextHighlightStyle, ]} + {...dropdownTextProps} > {item} diff --git a/expo-example/ModalDropdown.js b/expo-example/ModalDropdown.js index cf092b3..8a98802 100644 --- a/expo-example/ModalDropdown.js +++ b/expo-example/ModalDropdown.js @@ -355,6 +355,7 @@ export default class ModalDropdown extends Component { dropdownTextStyle, dropdownTextHighlightStyle, accessible, + dropdownTextProps, } = this.props; const RowTouchable = renderRowComponent; const { selectedIndex } = this.state; @@ -369,6 +370,7 @@ export default class ModalDropdown extends Component { highlighted && styles.highlightedRowText, highlighted && dropdownTextHighlightStyle, ]} + {...dropdownTextProps} > {item}