Skip to content
Open
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ class SampleApp extends Component {
data={data}
initValue="Select something yummy!"
onChange={(option)=>{ this.setState({textInputValue:option.label})}}>

<TextInput
style={{borderWidth:1, borderColor:'#ccc', padding:10, height:30}}
editable={false}
placeholder="Select something yummy!"
value={this.state.textInputValue} />

</ModalPicker>
</View>
);
Expand All @@ -86,6 +86,7 @@ class SampleApp extends Component {
* `data - []` required, array of objects with a unique key and label
* `style - object` optional, style definitions for the root element
* `onChange - function` optional, callback function, when the users has selected an option
* `onClose - function` optional, callback function, when the modal is closed
* `initValue - string` optional, text that is initially shown on the button
* `cancelText - string` optional, text of the cancel button
* `selectStyle - object` optional, style definitions for the select element (available in default mode only!)
Expand Down
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let componentIndex = 0;
const propTypes = {
data: PropTypes.array,
onChange: PropTypes.func,
onClose: PropTypes.func,
initValue: PropTypes.string,
style: View.propTypes.style,
selectStyle: View.propTypes.style,
Expand All @@ -39,6 +40,7 @@ const propTypes = {
const defaultProps = {
data: [],
onChange: ()=> {},
onClose: ()=> {},
initValue: 'Select me!',
style: {},
selectStyle: {},
Expand All @@ -60,6 +62,7 @@ export default class ModalPicker extends BaseComponent {

this._bind(
'onChange',
'onClose',
'open',
'close',
'renderChildren'
Expand All @@ -69,7 +72,8 @@ export default class ModalPicker extends BaseComponent {
animationType: 'slide',
modalVisible: false,
transparent: false,
selected: 'please select'
selected: 'please select',
selectedObject: {},
};
}

Expand All @@ -84,12 +88,23 @@ export default class ModalPicker extends BaseComponent {
}
}

componentWillUpdate(nextProps, nextState){
if (nextState.modalVisible != this.state.modalVisible && nextState.modalVisible === false)
{
this.onClose(nextState.selectedObject);
}
}

onChange(item) {
this.props.onChange(item);
this.setState({selected: item.label});
this.setState({selected: item.label, selectedObject: item});
this.close();
}

onClose(item) {
this.props.onClose(item);
}

close() {
this.setState({
modalVisible: false
Expand Down