Skip to content

Commit

Permalink
use iconRenderer as Icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
renrizzolo committed May 31, 2019
1 parent f44dad9 commit c3146e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/components/ItemIcon.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Image } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
// import Icon from 'react-native-vector-icons/MaterialIcons'

const ItemIcon = ({ icon, iconKey, itemIconStyle }) => {
const ItemIcon = ({ iconRenderer: Icon, icon, iconKey, itemIconStyle }) => {
return (
typeof icon === 'object' || typeof icon === 'number' ?
<Image
Expand Down
16 changes: 12 additions & 4 deletions lib/components/RowItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class RowItem extends Component {
}

shouldComponentUpdate(nextProps, nextState) {

if (nextProps.selectedItems !== this.props.selectedItems) {
if (
this.props.selectedItems.includes(this.props.item[this.props.uniqueKey]) &&
Expand Down Expand Up @@ -70,7 +69,6 @@ class RowItem extends Component {
) {
return true
}

}

if (this.props.searchTerm !== nextProps.searchTerm) {
Expand Down Expand Up @@ -172,7 +170,11 @@ class RowItem extends Component {
)
_renderSelectedIcon = () => {
const {
item, selectedIconComponent, mergedColors, unselectedIconComponent,
item,
selectedIconComponent,
mergedColors,
unselectedIconComponent,
iconRenderer: Icon,
} = this.props
return this._itemSelected(item)
? callIfFunction(selectedIconComponent) || (
Expand Down Expand Up @@ -205,6 +207,7 @@ class RowItem extends Component {
displayKey,
selectedItems,
iconKey,
iconRenderer: Icon,
} = this.props
const hasDropDown = item[subKey] && item[subKey].length > 0 && showDropDowns

Expand Down Expand Up @@ -235,7 +238,12 @@ class RowItem extends Component {
>
{selectedIconOnLeft && this._renderSelectedIcon()}
{iconKey && item[iconKey] && (
<ItemIcon iconKey={iconKey} icon={item[iconKey]} style={mergedStyles.itemIconStyle} />
<ItemIcon
iconRenderer={Icon}
iconKey={iconKey}
icon={item[iconKey]}
style={mergedStyles.itemIconStyle}
/>
)}
<Text
numberOfLines={itemNumberOfLines}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/RowSubItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { View, TouchableOpacity, Text, Image } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
import ItemIcon from './ItemIcon'
import { callIfFunction } from '../helpers'

Expand Down Expand Up @@ -54,6 +53,7 @@ class RowSubItem extends Component {
highlightedChildren,
uniqueKey,
subItem,
iconRenderer: Icon,
} = this.props
const highlightChild = !selectChildren && highlightedChildren.includes(subItem[uniqueKey])
const itemSelected = this._itemSelected()
Expand Down

0 comments on commit c3146e3

Please sign in to comment.