From 1fd27dae5e498efb5a12e5eb6350540b25c48696 Mon Sep 17 00:00:00 2001 From: Hedger Wang Date: Thu, 17 Sep 2015 17:03:23 -0700 Subject: [PATCH] Fix crash on RC while toggling object status. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed By: @​chaceliang Differential Revision: D2454891 --- .../Components/SwitchAndroid/SwitchAndroid.android.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/SwitchAndroid/SwitchAndroid.android.js b/Libraries/Components/SwitchAndroid/SwitchAndroid.android.js index 1d4d60495..f53aff7c2 100644 --- a/Libraries/Components/SwitchAndroid/SwitchAndroid.android.js +++ b/Libraries/Components/SwitchAndroid/SwitchAndroid.android.js @@ -51,12 +51,16 @@ var SwitchAndroid = React.createClass({ }, _onChange: function(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({on: 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() {