Skip to content

Commit

Permalink
allow render custom search component in Picker options list
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanshar committed Oct 16, 2018
1 parent 25e88fb commit 15992f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/picker/PickerModal.js
Expand Up @@ -25,6 +25,7 @@ class PickerModal extends BaseComponent {
}),
searchPlaceholder: PropTypes.string,
onSearchChange: PropTypes.func,
renderCustomSearch: PropTypes.func,
listProps: PropTypes.object,
};

Expand All @@ -43,8 +44,13 @@ class PickerModal extends BaseComponent {
}

renderSearchInput() {
const {showSearch, searchStyle, searchPlaceholder, onSearchChange} = this.props;
const {showSearch, searchStyle, searchPlaceholder, onSearchChange, renderCustomSearch} = this.props;

if (showSearch) {
if (_.isFunction(renderCustomSearch)) {
return renderCustomSearch(this.props);
}

return (
<View style={this.styles.searchInputContainer}>
<Image style={this.styles.searchIcon} source={Assets.icons.search} />
Expand Down
15 changes: 14 additions & 1 deletion src/components/picker/index.js
Expand Up @@ -105,6 +105,10 @@ class Picker extends TextInput {
* callback for picker modal search input text change
*/
onSearchChange: PropTypes.func,
/**
* Render custom search input
*/
renderCustomSearch: PropTypes.func,
/**
* Allow to use the native picker solution (different for iOS and Android)
*/
Expand Down Expand Up @@ -269,7 +273,15 @@ class Picker extends TextInput {
}

renderExpandableModal() {
const {mode, enableModalBlur, topBarProps, showSearch, searchStyle, searchPlaceholder, listProps} = this.getThemeProps();
const {
mode,
enableModalBlur,
topBarProps,
showSearch,
searchStyle,
searchPlaceholder,
renderCustomSearch,
listProps} = this.getThemeProps();
const {showExpandableModal, selectedItemPosition} = this.state;
return (
<PickerModal
Expand All @@ -285,6 +297,7 @@ class Picker extends TextInput {
searchStyle={searchStyle}
searchPlaceholder={searchPlaceholder}
onSearchChange={this.onSearchChange}
renderCustomSearch={renderCustomSearch}
listProps={listProps}
>
{this.appendPropsToChildren(this.props.children)}
Expand Down

0 comments on commit 15992f5

Please sign in to comment.