From 3d01ca9fb7878ede59ca7f62d62e46557375af64 Mon Sep 17 00:00:00 2001 From: home3k Date: Wed, 3 Aug 2016 23:35:14 +0800 Subject: [PATCH 1/4] fix --- README.md | 2 ++ index.js | 82 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 882c020..c6398c0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # react-native-multiple-choice A cross-platform (iOS / Android) single and multiple-choice React Native component. +fix bug by home3k. + ## Install ```sh diff --git a/index.js b/index.js index a9037fe..c7e3988 100644 --- a/index.js +++ b/index.js @@ -29,9 +29,9 @@ const defaultProps = { options: [], selectedOptions: [], onSelection(option){}, - style:{}, - optionStyle:{}, - disabled: false +style:{}, +optionStyle:{}, +disabled: false }; class MultipleChoice extends BaseComponent { @@ -39,7 +39,7 @@ class MultipleChoice extends BaseComponent { constructor(props) { super(props); - const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => true}); + const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) this.ds = ds; this.state = { @@ -49,23 +49,24 @@ class MultipleChoice extends BaseComponent { }; this._bind( - '_renderRow', - '_selectOption', - '_isSelected', - '_updateSelectedOptions' + '_renderRow', + '_selectOption', + '_isSelected', + '_updateSelectedOptions' ); } componentWillReceiveProps(nextProps) { - this._updateSelectedOptions(nextProps.selectedOptions); + console.info('rec', nextProps) + this._updateSelectedOptions(nextProps.selectedOptions, nextProps.options); this.setState({ disabled: nextProps.disabled }); } - _updateSelectedOptions(selectedOptions) { + _updateSelectedOptions(selectedOptions, options) { this.setState({ selectedOptions, - dataSource: this.ds.cloneWithRows(this.props.options) + dataSource: this.ds.cloneWithRows(options) }); } @@ -109,11 +110,11 @@ class MultipleChoice extends BaseComponent { } return ( - - ); + + ); } } @@ -136,6 +137,7 @@ class MultipleChoice extends BaseComponent { } _renderRow(option) { + console.log('render row', option) if(typeof this.props.renderRow === 'function') { return this.props.renderRow(option); @@ -144,33 +146,35 @@ class MultipleChoice extends BaseComponent { const disabled = this.state.disabled; return ( - - {this._selectOption(option)} : null} - > - - - {this._renderText(option)} - {this._renderIndicator(option)} - - - - {this._renderSeparator(option)} - - ); + + {this._selectOption(option)} : null} + > + + + {this._renderText(option)} + {this._renderIndicator(option)} + + + + {this._renderSeparator(option)} + + ); } render() { + console.log(this.state.dataSource) return ( - - ); + + ); } }; From 214f6c7b602213a79d984e33e4338434c1d2f821 Mon Sep 17 00:00:00 2001 From: home3k Date: Wed, 3 Aug 2016 23:48:29 +0800 Subject: [PATCH 2/4] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c7e3988..1de5730 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,7 @@ class MultipleChoice extends BaseComponent { _updateSelectedOptions(selectedOptions, options) { this.setState({ selectedOptions, - dataSource: this.ds.cloneWithRows(options) + dataSource: options ? this.ds.cloneWithRows(options) : this.ds.cloneWithRows(this.props.options) }); } From bb180746591f09913e27cdc7892171b3b64611f3 Mon Sep 17 00:00:00 2001 From: home3k Date: Thu, 4 Aug 2016 10:32:55 +0800 Subject: [PATCH 3/4] fix --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c6398c0..882c020 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # react-native-multiple-choice A cross-platform (iOS / Android) single and multiple-choice React Native component. -fix bug by home3k. - ## Install ```sh From fc6696d451d7ad2e4cfb52044c732382fcf3fc2a Mon Sep 17 00:00:00 2001 From: home3k Date: Thu, 4 Aug 2016 10:39:42 +0800 Subject: [PATCH 4/4] kick console. --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index 1de5730..932d49e 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,6 @@ class MultipleChoice extends BaseComponent { } componentWillReceiveProps(nextProps) { - console.info('rec', nextProps) this._updateSelectedOptions(nextProps.selectedOptions, nextProps.options); this.setState({ disabled: nextProps.disabled @@ -166,7 +165,6 @@ class MultipleChoice extends BaseComponent { } render() { - console.log(this.state.dataSource) return (