Skip to content

Commit

Permalink
Adds props to allow custom rendering of RouSubItem content
Browse files Browse the repository at this point in the history
  • Loading branch information
OrLavy committed Jun 19, 2019
1 parent b77d6c4 commit 1c9fd02
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 42 deletions.
17 changes: 11 additions & 6 deletions lib/components/RowItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RowItem extends Component {
) {
return true
}

}

if (this.props.searchTerm !== nextProps.searchTerm) {
Expand All @@ -82,6 +82,11 @@ class RowItem extends Component {
if (this.props.mergedStyles !== nextProps.mergedStyles) {
return true
}

if (this.props.costumeSubItemContentRender !== nextProps.costumeSubItemContentRender) {
return true
}

return false
}

Expand Down Expand Up @@ -179,12 +184,12 @@ class RowItem extends Component {
<Icon
name="check"
style={{
fontSize: 16,
color: mergedColors.success,
paddingLeft: 10,
}}
fontSize: 16,
color: mergedColors.success,
paddingLeft: 10,
}}
/>
)
)
: callIfFunction(unselectedIconComponent) || null
}

Expand Down
88 changes: 59 additions & 29 deletions lib/components/RowSubItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types'
import { View, TouchableOpacity, Text, Image } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
Expand Down Expand Up @@ -32,6 +32,9 @@ class RowSubItem extends Component {
if (this.props.mergedStyles !== nextProps.mergedStyles) {
return true
}
if (this.props.customSubItemContentRenderer !== nextProps.customSubItemContentRenderer) {
return true
}
return false
}

Expand Down Expand Up @@ -77,24 +80,72 @@ class RowSubItem extends Component {
) : null
}

render() {
_renderDefaultContent = () => {
const {
mergedStyles,
mergedColors,
subItem,
selectChildren,
selectedIconOnLeft,
iconKey,
uniqueKey,
displayKey,
itemNumberOfLines,
subItemFontFamily,
highlightedChildren,
} = this.props;

const itemSelected = this._itemSelected();
const highlightChild = !selectChildren && highlightedChildren.includes(subItem[uniqueKey])

return (
<Fragment>
{selectedIconOnLeft && this._renderSelectedIcon()}

{iconKey && subItem[iconKey] && (
<ItemIcon
iconKey={iconKey}
icon={subItem[iconKey]}
style={mergedStyles.itemIconStyle}
/>
)}
<Text
numberOfLines={itemNumberOfLines}
style={[
{
flex: 1,
color: subItem.disabled ? mergedColors.disabled : mergedColors.subText,
},
subItemFontFamily,
mergedStyles.subItemText,
(itemSelected || highlightChild) && mergedStyles.selectedSubItemText,
]}
>
{subItem[displayKey]}
</Text>
{!selectedIconOnLeft && this._renderSelectedIcon()}
</Fragment>
)
}

render() {
const {
mergedStyles,
mergedColors,
subItem,
uniqueKey,
selectChildren,
selectedIconOnLeft,
highlightedChildren,
itemNumberOfLines,
displayKey,
iconKey,

// OL_CHANGE
customSubItemContentRenderer: CustomSubItemContentRenderer
} = this.props

const highlightChild = !selectChildren && highlightedChildren.includes(subItem[uniqueKey])
const itemSelected = this._itemSelected()

const shouldUseCostumeRender = CustomSubItemContentRenderer ? true : false;

return (
<View
key={subItem[uniqueKey]}
Expand All @@ -120,30 +171,9 @@ class RowSubItem extends Component {
(itemSelected || highlightChild) && mergedStyles.selectedSubItem,
]}
>
{selectedIconOnLeft && this._renderSelectedIcon()}
{!shouldUseCostumeRender && this._renderDefaultContent()}

{iconKey && subItem[iconKey] && (
<ItemIcon
iconKey={iconKey}
icon={subItem[iconKey]}
style={mergedStyles.itemIconStyle}
/>
)}
<Text
numberOfLines={itemNumberOfLines}
style={[
{
flex: 1,
color: subItem.disabled ? mergedColors.disabled : mergedColors.subText,
},
subItemFontFamily,
mergedStyles.subItemText,
(itemSelected || highlightChild) && mergedStyles.selectedSubItemText,
]}
>
{subItem[displayKey]}
</Text>
{!selectedIconOnLeft && this._renderSelectedIcon()}
{shouldUseCostumeRender && <CustomSubItemContentRenderer subItem={subItem} isItemSelected={this._itemSelected}/> }
</TouchableOpacity>
</View>
)
Expand Down
15 changes: 8 additions & 7 deletions lib/sectioned-multi-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class SectionedMultiSelect extends PureComponent {
dropDownToggleIconUpComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
dropDownToggleIconDownComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
chipRemoveIconComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
customSubItemContentRenderer: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
selectChildren: PropTypes.bool,
highlightChildren: PropTypes.bool,
onSelectedItemObjectsChange: PropTypes.func,
Expand Down Expand Up @@ -951,13 +952,13 @@ class SectionedMultiSelect extends PureComponent {
onRequestClose={this._closeSelector}
>
<this.BackdropView
style={[{
flex: 1,
width: '100%',
height: '100%',
position: 'absolute',
style={[{
flex: 1,
width: '100%',
height: '100%',
position: 'absolute',
backgroundColor: 'rgba(0,0,0,0.5)',
zIndex: 0
zIndex: 0
}, styles.backdrop]}
/>
<View
Expand Down Expand Up @@ -1117,7 +1118,7 @@ class SectionedMultiSelect extends PureComponent {
styles.selectToggle,
]}
>
{this._getSelectLabel()}
{this._getSelectLabel()}
{callIfFunction(selectToggleIconComponent) || (
<Icon
size={24}
Expand Down

0 comments on commit 1c9fd02

Please sign in to comment.