Fix crash on RC while toggling object status.

Reviewed By: @​chaceliang

Differential Revision: D2446382
This commit is contained in:
Hedger Wang 2015-09-16 15:31:08 -07:00 committed by facebook-github-bot-7
parent 674abf1955
commit bab9bfec3a
1 changed files with 7 additions and 3 deletions

View File

@ -81,12 +81,16 @@ var SwitchIOS = React.createClass({
},
_onChange: function(event: Event) {
this.props.onChange && this.props.onChange(event);
this.props.onValueChange && this.props.onValueChange(event.nativeEvent.value);
// The underlying switch might have changed, but we're controlled,
// and so want to ensure it represents our value.
this.refs[SWITCH].setNativeProps({value: this.props.value});
if (this.props.value === event.nativeEvent.value || this.props.disabled) {
return;
}
this.props.onChange && this.props.onChange(event);
this.props.onValueChange && this.props.onValueChange(event.nativeEvent.value);
},
render: function() {