@@ -15,6 +15,9 @@ const DEFAULT_COLOR = Colors.blue30;
15
15
const DEFAULT_ICON_COLOR = Colors . white ;
16
16
const DEFAULT_DISABLED_COLOR = Colors . grey50 ;
17
17
18
+ const DEFAULT_BORDER_WIDTH = 2 ;
19
+ const DEFAULT_BORDER_RADIUS = 8 ;
20
+
18
21
export interface CheckboxProps extends TouchableOpacityProps {
19
22
/**
20
23
* The value of the Checkbox. If true the switch will be turned on. Default value is false.
@@ -163,14 +166,15 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
163
166
}
164
167
} ;
165
168
166
- getColor ( ) {
167
- const { color, disabled} = this . props ;
168
- return disabled ? DEFAULT_DISABLED_COLOR : color || DEFAULT_COLOR ;
169
- }
169
+ getColor = ( ) => this . props . disabled ? DEFAULT_DISABLED_COLOR : this . props . color || DEFAULT_COLOR ;
170
+
171
+ getBackgroundColor = ( ) => this . props . outline ? 'transparent' : this . getColor ( ) ;
172
+
173
+ getTintColor = ( ) => this . props . outline ? this . getColor ( ) : DEFAULT_ICON_COLOR ;
170
174
171
175
getBorderStyle ( ) {
172
176
const borderColor = { borderColor : this . getColor ( ) } ;
173
- const borderStyle = [ this . styles . container , { borderWidth : 2 } , borderColor ] ;
177
+ const borderStyle = [ this . styles . container , { borderWidth : DEFAULT_BORDER_WIDTH } , borderColor ] ;
174
178
175
179
return borderStyle ;
176
180
}
@@ -185,7 +189,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
185
189
testID,
186
190
style,
187
191
containerStyle,
188
- outline = false ,
192
+ outline,
189
193
...others
190
194
} = this . props ;
191
195
@@ -203,16 +207,15 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
203
207
< Animated . View
204
208
style = { [
205
209
this . styles . container ,
206
- { backgroundColor : outline ? 'transparent' : disabled ? DEFAULT_DISABLED_COLOR : this . getColor ( ) } ,
207
- { opacity : this . animationStyle . opacity }
210
+ { opacity : this . animationStyle . opacity } ,
211
+ { backgroundColor : this . getBackgroundColor ( ) }
208
212
] }
209
213
>
210
214
< Animated . Image
211
215
style = { [
212
216
this . styles . selectedIcon ,
213
- color && { tintColor : outline ? this . getColor ( ) : DEFAULT_ICON_COLOR } ,
214
217
{ transform : this . animationStyle . transform } ,
215
- disabled && { tintColor : outline ? DEFAULT_DISABLED_COLOR : DEFAULT_ICON_COLOR }
218
+ { tintColor : this . getTintColor ( ) }
216
219
] }
217
220
source = { selectedIcon || Assets . icons . checkSmall }
218
221
testID = { `${ testID } .selected` }
@@ -239,19 +242,19 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
239
242
}
240
243
241
244
function createStyles ( props : CheckboxProps ) {
242
- const { color = DEFAULT_COLOR , iconColor = DEFAULT_ICON_COLOR , size = DEFAULT_SIZE , borderRadius, outline , disabled } = props ;
245
+ const { color = DEFAULT_COLOR , iconColor = DEFAULT_ICON_COLOR , size = DEFAULT_SIZE , borderRadius = DEFAULT_BORDER_RADIUS } = props ;
243
246
244
247
return StyleSheet . create ( {
245
248
container : {
246
249
width : size ,
247
250
height : size ,
248
- borderRadius : borderRadius || 8 ,
251
+ borderRadius : borderRadius ,
249
252
alignItems : 'center' ,
250
253
justifyContent : 'center' ,
251
254
borderColor : color
252
255
} ,
253
256
selectedIcon : {
254
- tintColor : disabled ? DEFAULT_DISABLED_COLOR : outline ? color : iconColor ,
257
+ tintColor : iconColor ,
255
258
alignItems : 'center' ,
256
259
justifyContent : 'center'
257
260
} ,
0 commit comments