react-native-modal-selector
Advanced tools
Comparing version 1.0.2 to 1.0.3
23
index.js
@@ -74,2 +74,3 @@ 'use strict'; | ||
customSelector: PropTypes.node, | ||
selectedKey: PropTypes.any, | ||
}; | ||
@@ -110,3 +111,3 @@ | ||
backdropPressToClose: false, | ||
openButtonContainerAccessible: false, | ||
openButtonContainerAccessible: false, | ||
listItemAccessible: false, | ||
@@ -122,2 +123,3 @@ cancelButtonAccessible: false, | ||
customSelector: undefined, | ||
selectedKey: '', | ||
}; | ||
@@ -129,8 +131,8 @@ | ||
super(props); | ||
let selectedItem = this.validateSelectedKey(props.selectedKey); | ||
this.state = { | ||
modalVisible: props.visible, | ||
selected: props.initValue, | ||
selected: selectedItem.label, | ||
cancelText: props.cancelText, | ||
changedItem: undefined, | ||
changedItem: selectedItem.key, | ||
}; | ||
@@ -150,2 +152,8 @@ } | ||
} | ||
if(prevProps.selectedKey !== this.props.selectedKey){ | ||
let selectedItem = this.validateSelectedKey(this.props.selectedKey); | ||
newState.selected = selectedItem.label; | ||
newState.changedItem = selectedItem.key; | ||
doUpdate = true; | ||
} | ||
if (doUpdate) { | ||
@@ -156,2 +164,9 @@ this.setState(newState); | ||
validateSelectedKey = (key) => { | ||
let selectedItem = this.props.data.filter((item) => this.props.keyExtractor(item) === key); | ||
let selectedLabel = selectedItem.length > 0 ? this.props.labelExtractor(selectedItem[0]) : this.props.initValue; | ||
let selectedKey = selectedItem.length > 0 ? key : undefined; | ||
return {label: selectedLabel, key: selectedKey} | ||
} | ||
onChange = (item) => { | ||
@@ -158,0 +173,0 @@ if (Platform.OS === 'android' || (Modal.propTypes !== undefined && !Modal.propTypes.onDismiss)) { // don't know if this will work for previous version, please check! |
{ | ||
"name": "react-native-modal-selector", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -167,2 +167,3 @@ # react-native-modal-selector [](https://badge.fury.io/js/react-native-modal-selector) | ||
`customSelector` | node | Yes | undefined | Render a custom node instead of the built-in select box. | ||
`selectedKey` | any | Yes | '' | Key of the item to be initially selected | ||
@@ -169,0 +170,0 @@ ### Methods |
71644
357
172