Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new Icon beside <Text> tag of the list item #87

Merged
merged 2 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const items = [
{
name: "Fruits",
id: 0,
icon: "https://images.vexels.com/media/users/3/147164/isolated/preview/6bf92415c7b2651f512aa0db5a3e1aba-red-apple-icon-fruit-by-vexels.png"
children: [{
name: "Apple",
id: 10,
Expand All @@ -59,6 +60,7 @@ const items = [
{
name: "Gems",
id: 1,
icon: "https://cdn4.iconfinder.com/data/icons/free-crystal-icons/512/Gemstone.png"
children: [{
name: "Quartz",
id: 20,
Expand All @@ -76,6 +78,7 @@ const items = [
{
name: "Plants",
id: 2,
icon: "https://banner2.kisspng.com/20180514/wqq/kisspng-leaf-plant-green-clip-art-5af9b5b7402440.7747356215263144232627.jpg"
children: [{
name: "Mother In Law\'s Tongue",
id: 30,
Expand Down Expand Up @@ -111,6 +114,7 @@ export default class App extends Component {
items={items}
uniqueKey='id'
subKey='children'
iconKey='key'
selectText='Choose some things...'
showDropDowns={true}
readOnlyHeadings={true}
Expand Down Expand Up @@ -155,16 +159,17 @@ Props, there are lots.
### Main
| Prop | Default | type | Desc |
| ------------- |------------- | ----- |----- |
|items | | array |the items |
|items | | array |the items |
|uniqueKey | 'id' | string |the unique key for your items |
|subKey | 'sub' | string |the array of sub items within items |
|displayKey | 'name' | string |the key for the display name / title of the item |
|subKey | 'sub' | string |the array of sub items within items |
|displayKey | 'name' | string |the key for the display name / title of the item |
|iconKey | 'icon' | string |the key for the display icon / bitmap of the item |
|selectedItems | [] | array |the selected items |
|onSelectedItemsChange | | function |function that runs when an item is toggled|
|onSelectedItemObjectsChange | | function |function that returns the selected items as their original objects instead of an array of ids |
|onCancel | | function |function that runs when the cancel button is pressed |
|onConfirm | | function |function that runs when the confirm button is pressed |
|onToggleSelector | | function |callback function that runs when the selector is toggled. receives a boolean for the open/close state of the modal |
|onSelectedItemsChange | | function |function that runs when an item is toggled|
|onSelectedItemObjectsChange | | function |function that returns the selected items as their original objects instead of an array of ids |
|onCancel | | function |function that runs when the cancel button is pressed |
|onConfirm | | function |function that runs when the confirm button is pressed |
|onToggleSelector | | function |callback function that runs when the selector is toggled. receives a boolean for the open/close state of the modal |

### Options

Expand Down Expand Up @@ -275,3 +280,4 @@ These are the styles you can change:
`button`
`confirmText`
`cancelButton`
`itemIconStyle`
12 changes: 10 additions & 2 deletions lib/components/RowItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
UIManager,
LayoutAnimation,
FlatList,
StyleSheet
StyleSheet,
Image
} from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
import RowSubItem from './RowSubItem'
Expand Down Expand Up @@ -163,6 +164,7 @@ class RowItem extends Component {
itemNumberOfLines,
displayKey,
selectedItems,
iconKey
} = this.props
const hasDropDown = item[subKey] && item[subKey].length > 0 && showDropDowns

Expand All @@ -187,6 +189,12 @@ class RowItem extends Component {
paddingVertical: 6,
}, mergedStyles.item, this._itemSelected(item) && mergedStyles.selectedItem]}
>

{iconKey && item[iconKey] && <Image source={item[iconKey]} style={[{
width:16,
marginHorizontal:10
}, mergedStyles.itemIconStyle ]} />}

<Text
numberOfLines={itemNumberOfLines}
style={
Expand All @@ -198,7 +206,7 @@ class RowItem extends Component {
mergedStyles.itemText, this._itemSelected(item) && mergedStyles.selectedItemText
]}
>
{item[displayKey]}
{item[displayKey]}
</Text>
{
this._itemSelected(item) ?
Expand Down
50 changes: 28 additions & 22 deletions lib/components/RowSubItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RowSubItem extends Component {
highlightedChildren,
itemNumberOfLines,
displayKey,
iconKey
} = this.props

const highlightChild = !selectChildren && highlightedChildren.includes(subItem[uniqueKey])
Expand All @@ -80,39 +81,44 @@ class RowSubItem extends Component {
paddingVertical: 6,
}, mergedStyles.subItem, (itemSelected || highlightChild) && mergedStyles.selectedItem]}
>
{iconKey && item[iconKey] && <Image source={item[iconKey]} style={[{
width: 16,
marginHorizontal: 10
}, mergedStyles.itemIconStyle]} />}

<Text
numberOfLines={itemNumberOfLines}
style={
[{
flex: 1,
flex: 1,
color: subItem.disabled ? mergedColors.disabled : mergedColors.subText,
},
subItemFontFamily,
mergedStyles.subItemText,
(itemSelected || highlightChild) && mergedStyles.selectedSubItemText,
},
subItemFontFamily,
mergedStyles.subItemText,
(itemSelected || highlightChild) && mergedStyles.selectedSubItemText,
]
}
>
{subItem[displayKey]}
</Text>
{
itemSelected || highlightChild ?
<View>
{ selectedIconComponent ?
selectedIconComponent
:
<Icon
name="check"
style={{
fontSize: 16,
color: highlightChild ? mergedColors.disabled : mergedColors.success,
paddingLeft: 10,
}}
/>
}
</View>
:
null
itemSelected || highlightChild ?
<View>
{ selectedIconComponent ?
selectedIconComponent
:
<Icon
name="check"
style={{
fontSize: 16,
color: highlightChild ? mergedColors.disabled : mergedColors.success,
paddingLeft: 10,
}}
/>
}
</View>
:
null
}
</TouchableOpacity>
</View>
Expand Down