mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 22:58:19 +00:00
Summary: fixes #23962, where trackColor is reset when value changed. This PR will set trackColor corresponding trackColor every-time value changes. [Android] [Changed] - Fix Switch trackColor Pull Request resolved: https://github.com/facebook/react-native/pull/23977 Differential Revision: D14495206 Pulled By: hramos fbshipit-source-id: d712f540cd3f8359d6e85f79c12732689870a112
This commit is contained in:
parent
4260907b90
commit
becc15468f
@ -54,6 +54,10 @@ class BasicSwitchExample extends React.Component<
|
||||
<Switch
|
||||
testID="on-off-initial-off"
|
||||
onValueChange={value => this.setState({falseSwitchIsOn: value})}
|
||||
trackColor={{
|
||||
true: 'yellow',
|
||||
false: 'purple',
|
||||
}}
|
||||
value={this.state.falseSwitchIsOn}
|
||||
/>
|
||||
<OnOffIndicator
|
||||
|
@ -36,6 +36,7 @@ import javax.annotation.Nullable;
|
||||
if (mAllowChange && isChecked() != checked) {
|
||||
mAllowChange = false;
|
||||
super.setChecked(checked);
|
||||
setTrackColor(checked);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,12 +60,7 @@ 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);
|
||||
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);
|
||||
}
|
||||
setTrackColor(on);
|
||||
}
|
||||
mAllowChange = true;
|
||||
}
|
||||
@ -90,4 +86,13 @@ import javax.annotation.Nullable;
|
||||
setTrackColor(mTrackColorForFalse);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTrackColor(boolean checked) {
|
||||
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 = checked ? mTrackColorForTrue : mTrackColorForFalse;
|
||||
setTrackColor(currentTrackColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user