@@ -25,12 +25,8 @@ type SwitchProps = {
25
25
disabled ?: boolean ,
26
26
onValueChange ?: ( e : any ) => void ,
27
27
thumbColor ?: ColorValue ,
28
- trackColor ?: ColorValue ,
29
- value ?: boolean ,
30
- // RN compat
31
- onTintColor ?: ColorValue ,
32
- thumbTintColor ?: ColorValue ,
33
- tintColor ?: ColorValue
28
+ trackColor ?: ColorValue | { | false : ColorValue , true : ColorValue | } ,
29
+ value ?: boolean
34
30
} ;
35
31
36
32
const emptyObject = { } ;
@@ -62,10 +58,6 @@ class Switch extends React.Component<SwitchProps> {
62
58
thumbColor = '#FAFAFA' ,
63
59
trackColor = '#939393' ,
64
60
value = false ,
65
- // React Native compatibility
66
- onTintColor,
67
- thumbTintColor,
68
- tintColor,
69
61
...other
70
62
} = this . props ;
71
63
@@ -74,30 +66,33 @@ class Switch extends React.Component<SwitchProps> {
74
66
const minWidth = multiplyStyleLengthValue ( height , 2 ) ;
75
67
const width = styleWidth > minWidth ? styleWidth : minWidth ;
76
68
const trackBorderRadius = multiplyStyleLengthValue ( height , 0.5 ) ;
77
- const trackCurrentColor = value ? onTintColor || activeTrackColor : tintColor || trackColor ;
78
- const thumbCurrentColor = value ? activeThumbColor : thumbTintColor || thumbColor ;
69
+ const trackCurrentColor = value
70
+ ? ( trackColor != null && typeof trackColor === 'object' && trackColor . true ) ||
71
+ activeTrackColor
72
+ : ( trackColor != null && typeof trackColor === 'object' && trackColor . false ) || trackColor ;
73
+ const thumbCurrentColor = value ? activeThumbColor : thumbColor ;
79
74
const thumbHeight = height ;
80
75
const thumbWidth = thumbHeight ;
81
76
82
- const rootStyle = [ styles . root , style , { height , width } , disabled && styles . cursorDefault ] ;
77
+ const rootStyle = [ styles . root , style , disabled && styles . cursorDefault , { height , width } ] ;
83
78
84
79
const trackStyle = [
85
80
styles . track ,
86
81
{
87
- backgroundColor : trackCurrentColor ,
82
+ backgroundColor : disabled ? '#D5D5D5' : trackCurrentColor ,
88
83
borderRadius : trackBorderRadius
89
- } ,
90
- disabled && styles . disabledTrack
84
+ }
91
85
] ;
92
86
93
87
const thumbStyle = [
94
88
styles . thumb ,
89
+ value && styles . thumbActive ,
95
90
{
96
- backgroundColor : thumbCurrentColor ,
91
+ backgroundColor : disabled ? '#BDBDBD' : thumbCurrentColor ,
97
92
height : thumbHeight ,
93
+ marginStart : value ? multiplyStyleLengthValue ( thumbWidth , - 1 ) : 0 ,
98
94
width : thumbWidth
99
- } ,
100
- disabled && styles . disabledThumb
95
+ }
101
96
] ;
102
97
103
98
const nativeControl = createElement ( 'input' , {
@@ -115,16 +110,7 @@ class Switch extends React.Component<SwitchProps> {
115
110
return (
116
111
< View { ...other } style = { rootStyle } >
117
112
< View style = { trackStyle } />
118
- < View
119
- ref = { this . _setThumbRef }
120
- style = { [
121
- thumbStyle ,
122
- value && styles . thumbOn ,
123
- {
124
- marginStart : value ? multiplyStyleLengthValue ( thumbWidth , - 1 ) : 0
125
- }
126
- ] }
127
- />
113
+ < View ref = { this . _setThumbRef } style = { thumbStyle } />
128
114
{ nativeControl }
129
115
</ View >
130
116
) ;
@@ -170,9 +156,6 @@ const styles = StyleSheet.create({
170
156
transitionDuration : '0.1s' ,
171
157
width : '100%'
172
158
} ,
173
- disabledTrack : {
174
- backgroundColor : '#D5D5D5'
175
- } ,
176
159
thumb : {
177
160
alignSelf : 'flex-start' ,
178
161
borderRadius : '100%' ,
@@ -181,12 +164,9 @@ const styles = StyleSheet.create({
181
164
transform : [ { translateZ : 0 } ] ,
182
165
transitionDuration : '0.1s'
183
166
} ,
184
- thumbOn : {
167
+ thumbActive : {
185
168
start : '100%'
186
169
} ,
187
- disabledThumb : {
188
- backgroundColor : '#BDBDBD'
189
- } ,
190
170
nativeControl : {
191
171
...StyleSheet . absoluteFillObject ,
192
172
height : '100%' ,
0 commit comments