diff --git a/Libraries/Components/Switch/Switch.js b/Libraries/Components/Switch/Switch.js index 9bd00aaf1b0e42..ad928639748fd9 100644 --- a/Libraries/Components/Switch/Switch.js +++ b/Libraries/Components/Switch/Switch.js @@ -137,6 +137,8 @@ class Switch extends React.Component { on: value === true, style, thumbTintColor: _thumbColor, + trackColorForFalse: _trackColorForFalse, + trackColorForTrue: _trackColorForTrue, trackTintColor: value === true ? _trackColorForTrue : _trackColorForFalse, }: NativeAndroidProps) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java index 64d0d444816253..4dd299ccaa43ee 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitch.java @@ -59,8 +59,12 @@ public void setThumbColor(@Nullable Integer color) { // If the switch has a different value than the value sent by JS, we must change it. if (isChecked() != on) { super.setChecked(on); - Integer currentTrackColor = on ? mTrackColorForTrue : mTrackColorForFalse; - setTrackColor(currentTrackColor); + if (mTrackColorForTrue != null || mTrackColorForFalse != null) { + // Update the track color to reflect the new value. We only want to do this if these + // props were actually set from JS; otherwise we'll just reset the color to the default. + Integer currentTrackColor = on ? mTrackColorForTrue : mTrackColorForFalse; + setTrackColor(currentTrackColor); + } } mAllowChange = true; }