Skip to content

Commit 1c9fd02

Browse files
committed
Adds props to allow custom rendering of RouSubItem content
1 parent b77d6c4 commit 1c9fd02

File tree

3 files changed

+78
-42
lines changed

3 files changed

+78
-42
lines changed

lib/components/RowItem.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RowItem extends Component {
7070
) {
7171
return true
7272
}
73-
73+
7474
}
7575

7676
if (this.props.searchTerm !== nextProps.searchTerm) {
@@ -82,6 +82,11 @@ class RowItem extends Component {
8282
if (this.props.mergedStyles !== nextProps.mergedStyles) {
8383
return true
8484
}
85+
86+
if (this.props.costumeSubItemContentRender !== nextProps.costumeSubItemContentRender) {
87+
return true
88+
}
89+
8590
return false
8691
}
8792

@@ -179,12 +184,12 @@ class RowItem extends Component {
179184
<Icon
180185
name="check"
181186
style={{
182-
fontSize: 16,
183-
color: mergedColors.success,
184-
paddingLeft: 10,
185-
}}
187+
fontSize: 16,
188+
color: mergedColors.success,
189+
paddingLeft: 10,
190+
}}
186191
/>
187-
)
192+
)
188193
: callIfFunction(unselectedIconComponent) || null
189194
}
190195

lib/components/RowSubItem.js

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react'
1+
import React, { Component, Fragment } from 'react';
22
import PropTypes from 'prop-types'
33
import { View, TouchableOpacity, Text, Image } from 'react-native'
44
import Icon from 'react-native-vector-icons/MaterialIcons'
@@ -32,6 +32,9 @@ class RowSubItem extends Component {
3232
if (this.props.mergedStyles !== nextProps.mergedStyles) {
3333
return true
3434
}
35+
if (this.props.customSubItemContentRenderer !== nextProps.customSubItemContentRenderer) {
36+
return true
37+
}
3538
return false
3639
}
3740

@@ -77,24 +80,72 @@ class RowSubItem extends Component {
7780
) : null
7881
}
7982

80-
render() {
83+
_renderDefaultContent = () => {
8184
const {
8285
mergedStyles,
8386
mergedColors,
8487
subItem,
88+
selectChildren,
89+
selectedIconOnLeft,
90+
iconKey,
8591
uniqueKey,
92+
displayKey,
93+
itemNumberOfLines,
8694
subItemFontFamily,
95+
highlightedChildren,
96+
} = this.props;
97+
98+
const itemSelected = this._itemSelected();
99+
const highlightChild = !selectChildren && highlightedChildren.includes(subItem[uniqueKey])
100+
101+
return (
102+
<Fragment>
103+
{selectedIconOnLeft && this._renderSelectedIcon()}
104+
105+
{iconKey && subItem[iconKey] && (
106+
<ItemIcon
107+
iconKey={iconKey}
108+
icon={subItem[iconKey]}
109+
style={mergedStyles.itemIconStyle}
110+
/>
111+
)}
112+
<Text
113+
numberOfLines={itemNumberOfLines}
114+
style={[
115+
{
116+
flex: 1,
117+
color: subItem.disabled ? mergedColors.disabled : mergedColors.subText,
118+
},
119+
subItemFontFamily,
120+
mergedStyles.subItemText,
121+
(itemSelected || highlightChild) && mergedStyles.selectedSubItemText,
122+
]}
123+
>
124+
{subItem[displayKey]}
125+
</Text>
126+
{!selectedIconOnLeft && this._renderSelectedIcon()}
127+
</Fragment>
128+
)
129+
}
130+
131+
render() {
132+
const {
133+
mergedStyles,
134+
mergedColors,
135+
subItem,
136+
uniqueKey,
87137
selectChildren,
88-
selectedIconOnLeft,
89138
highlightedChildren,
90-
itemNumberOfLines,
91-
displayKey,
92-
iconKey,
139+
140+
// OL_CHANGE
141+
customSubItemContentRenderer: CustomSubItemContentRenderer
93142
} = this.props
94143

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

147+
const shouldUseCostumeRender = CustomSubItemContentRenderer ? true : false;
148+
98149
return (
99150
<View
100151
key={subItem[uniqueKey]}
@@ -120,30 +171,9 @@ class RowSubItem extends Component {
120171
(itemSelected || highlightChild) && mergedStyles.selectedSubItem,
121172
]}
122173
>
123-
{selectedIconOnLeft && this._renderSelectedIcon()}
174+
{!shouldUseCostumeRender && this._renderDefaultContent()}
124175

125-
{iconKey && subItem[iconKey] && (
126-
<ItemIcon
127-
iconKey={iconKey}
128-
icon={subItem[iconKey]}
129-
style={mergedStyles.itemIconStyle}
130-
/>
131-
)}
132-
<Text
133-
numberOfLines={itemNumberOfLines}
134-
style={[
135-
{
136-
flex: 1,
137-
color: subItem.disabled ? mergedColors.disabled : mergedColors.subText,
138-
},
139-
subItemFontFamily,
140-
mergedStyles.subItemText,
141-
(itemSelected || highlightChild) && mergedStyles.selectedSubItemText,
142-
]}
143-
>
144-
{subItem[displayKey]}
145-
</Text>
146-
{!selectedIconOnLeft && this._renderSelectedIcon()}
176+
{shouldUseCostumeRender && <CustomSubItemContentRenderer subItem={subItem} isItemSelected={this._itemSelected}/> }
147177
</TouchableOpacity>
148178
</View>
149179
)

lib/sectioned-multi-select.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class SectionedMultiSelect extends PureComponent {
151151
dropDownToggleIconUpComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
152152
dropDownToggleIconDownComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
153153
chipRemoveIconComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
154+
customSubItemContentRenderer: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
154155
selectChildren: PropTypes.bool,
155156
highlightChildren: PropTypes.bool,
156157
onSelectedItemObjectsChange: PropTypes.func,
@@ -951,13 +952,13 @@ class SectionedMultiSelect extends PureComponent {
951952
onRequestClose={this._closeSelector}
952953
>
953954
<this.BackdropView
954-
style={[{
955-
flex: 1,
956-
width: '100%',
957-
height: '100%',
958-
position: 'absolute',
955+
style={[{
956+
flex: 1,
957+
width: '100%',
958+
height: '100%',
959+
position: 'absolute',
959960
backgroundColor: 'rgba(0,0,0,0.5)',
960-
zIndex: 0
961+
zIndex: 0
961962
}, styles.backdrop]}
962963
/>
963964
<View
@@ -1117,7 +1118,7 @@ class SectionedMultiSelect extends PureComponent {
11171118
styles.selectToggle,
11181119
]}
11191120
>
1120-
{this._getSelectLabel()}
1121+
{this._getSelectLabel()}
11211122
{callIfFunction(selectToggleIconComponent) || (
11221123
<Icon
11231124
size={24}

0 commit comments

Comments
 (0)