@@ -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,31 +166,21 @@ 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
}
177
181
178
182
renderCheckbox ( ) {
179
- const {
180
- selectedIcon,
181
- color,
182
- iconColor,
183
- label,
184
- disabled,
185
- testID,
186
- style,
187
- containerStyle,
188
- outline = false ,
189
- ...others
190
- } = this . props ;
183
+ const { selectedIcon, color, iconColor, label, disabled, testID, style, containerStyle, outline, ...others } = this . props ;
191
184
192
185
return (
193
186
//@ts -ignore
@@ -203,16 +196,15 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
203
196
< Animated . View
204
197
style = { [
205
198
this . styles . container ,
206
- { backgroundColor : outline ? 'transparent' : disabled ? DEFAULT_DISABLED_COLOR : this . getColor ( ) } ,
207
- { opacity : this . animationStyle . opacity }
199
+ { opacity : this . animationStyle . opacity } ,
200
+ { backgroundColor : this . getBackgroundColor ( ) }
208
201
] }
209
202
>
210
203
< Animated . Image
211
204
style = { [
212
205
this . styles . selectedIcon ,
213
- color && { tintColor : outline ? this . getColor ( ) : DEFAULT_ICON_COLOR } ,
214
206
{ transform : this . animationStyle . transform } ,
215
- disabled && { tintColor : outline ? DEFAULT_DISABLED_COLOR : DEFAULT_ICON_COLOR }
207
+ { tintColor : this . getTintColor ( ) }
216
208
] }
217
209
source = { selectedIcon || Assets . icons . checkSmall }
218
210
testID = { `${ testID } .selected` }
@@ -239,19 +231,19 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
239
231
}
240
232
241
233
function createStyles ( props : CheckboxProps ) {
242
- const { color = DEFAULT_COLOR , iconColor = DEFAULT_ICON_COLOR , size = DEFAULT_SIZE , borderRadius, outline , disabled } = props ;
234
+ const { color = DEFAULT_COLOR , iconColor = DEFAULT_ICON_COLOR , size = DEFAULT_SIZE , borderRadius = DEFAULT_BORDER_RADIUS } = props ;
243
235
244
236
return StyleSheet . create ( {
245
237
container : {
246
238
width : size ,
247
239
height : size ,
248
- borderRadius : borderRadius || 8 ,
240
+ borderRadius : borderRadius ,
249
241
alignItems : 'center' ,
250
242
justifyContent : 'center' ,
251
243
borderColor : color
252
244
} ,
253
245
selectedIcon : {
254
- tintColor : disabled ? DEFAULT_DISABLED_COLOR : outline ? color : iconColor ,
246
+ tintColor : iconColor ,
255
247
alignItems : 'center' ,
256
248
justifyContent : 'center'
257
249
} ,
0 commit comments