mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 22:58:19 +00:00
Pass through track color values for true/false to native component
Summary: There's a bug in the OSS Switch component where the track color value is reset to the default value when the switch is toggled. It looks like the Java class resets the track color value in `setOn` (which fires in a press event): https://fburl.com/vmugfzja but these values aren't actually initialized from JS - in Switch.js we only pass through the current track color: https://fburl.com/vytekd0o. The React component already has an API for defining both true/false track colors. However, we should also make sure not to reset these values for people using the old API of `tintColor`/`onTintColor`, so I'm changing it to only reset the value when both of those props are null. Reviewed By: mdvacca Differential Revision: D14035007 fbshipit-source-id: 12d968076bd47d54deedbfc15b12ff3cd77e2fd0
This commit is contained in:
parent
392b0845ce
commit
4260907b90
@ -137,6 +137,8 @@ class Switch extends React.Component<Props> {
|
||||
on: value === true,
|
||||
style,
|
||||
thumbTintColor: _thumbColor,
|
||||
trackColorForFalse: _trackColorForFalse,
|
||||
trackColorForTrue: _trackColorForTrue,
|
||||
trackTintColor:
|
||||
value === true ? _trackColorForTrue : _trackColorForFalse,
|
||||
}: NativeAndroidProps)
|
||||
|
@ -59,8 +59,12 @@ import javax.annotation.Nullable;
|
||||
// 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user