From 63d8af6259c385cd9d641d190cebcdddf8a69276 Mon Sep 17 00:00:00 2001 From: Jaco Groenewald Date: Fri, 16 Dec 2016 09:13:32 +0200 Subject: [PATCH 1/2] Added an optional prop onClose --- index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d65bf4c0..be778d4e 100644 --- a/index.js +++ b/index.js @@ -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, @@ -39,6 +40,7 @@ const propTypes = { const defaultProps = { data: [], onChange: ()=> {}, + onClose: ()=> {}, initValue: 'Select me!', style: {}, selectStyle: {}, @@ -60,6 +62,7 @@ export default class ModalPicker extends BaseComponent { this._bind( 'onChange', + 'onClose', 'open', 'close', 'renderChildren' @@ -69,7 +72,8 @@ export default class ModalPicker extends BaseComponent { animationType: 'slide', modalVisible: false, transparent: false, - selected: 'please select' + selected: 'please select', + selectedObject: {}, }; } @@ -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 From da0241be2e4e4efffd450aa6ddfcc13c285bf248 Mon Sep 17 00:00:00 2001 From: Jaco Groenewald Date: Fri, 16 Dec 2016 09:18:20 +0200 Subject: [PATCH 2/2] Updated Readme to include onClose --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d382a18d..52d53e4a 100644 --- a/README.md +++ b/README.md @@ -67,13 +67,13 @@ class SampleApp extends Component { data={data} initValue="Select something yummy!" onChange={(option)=>{ this.setState({textInputValue:option.label})}}> - + - + ); @@ -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!)