Skip to content

Commit

Permalink
fix partially #41
Browse files Browse the repository at this point in the history
  • Loading branch information
moschan committed Aug 13, 2017
1 parent 3183ed3 commit 26d224c
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions lib/SimpleRadioButton.js
Expand Up @@ -11,41 +11,43 @@ var {
TouchableOpacity,
TouchableWithoutFeedback,
LayoutAnimation,
Platform,
UIManager
} = ReactNative

var RadioForm = createReactClass({
getInitialState: function () {
return {
is_active_index: this.props.initial
export default class RadioForm extends React.Component {
constructor(props) {
super(props);
this.state = {
is_active_index: props.initial
}
},

getDefaultProps: function () {
return {
radio_props: [],
initial: 0,
buttonColor: '#2196f3',
formHorizontal: false,
labelHorizontal: true,
animation: true,
labelColor: '#000',
disabled: false
if (Platform.OS === 'android') {
UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);
}
},

componentWillReceiveProps (newProps) {
this._renderButton = this._renderButton.bind(this);
}
static defaultProps = {
radio_props: [],
initial: 0,
buttonColor: '#2196f3',
formHorizontal: false,
labelHorizontal: true,
animation: true,
labelColor: '#000',
disabled: false
}
componentWillReceiveProps(newProps) {
if (newProps.initial !== this.state.is_active_index) {
this.setState({ is_active_index: newProps.initial })
}
},
}

updateIsActiveIndex: function(index) {
updateIsActiveIndex(index) {
this.setState({ is_active_index: index });
this.props.onPress(this.props.radio_props[index], index)
},
}

_renderButton: function (obj, i) {
_renderButton(obj, i) {
return (
<RadioButton
accessible={this.props.accessible}
Expand All @@ -72,9 +74,9 @@ var RadioForm = createReactClass({
}}
/>
)
},
}

render: function () {
render() {
var render_content = false
if (this.props.radio_props.length) {
render_content = this.props.radio_props.map(this._renderButton)
Expand All @@ -91,7 +93,7 @@ var RadioForm = createReactClass({
</View>
)
}
})
}

export class RadioButton extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -280,5 +282,3 @@ export class RadioButtonLabel extends React.Component {
)
}
}

export default RadioForm

0 comments on commit 26d224c

Please sign in to comment.