@@ -56,6 +56,7 @@ const transparentImage = require('./assets/transparentSwatch/TransparentSwatch.p
56
56
const DEFAULT_SIZE = Constants . isTablet ? 44 : 36 ;
57
57
export const SWATCH_MARGIN = 12 ;
58
58
export const SWATCH_SIZE = DEFAULT_SIZE ;
59
+ const DEFAULT_COLOR = Colors . grey30 ;
59
60
60
61
/**
61
62
* @description : A color swatch component
@@ -124,9 +125,8 @@ class ColorSwatch extends PureComponent<Props & BaseComponentInjectedProps> {
124
125
125
126
onPress = ( ) => {
126
127
const { value, index} = this . props ;
127
- const color = this . color ?? '' ;
128
128
const tintColor = this . getTintColor ( value ) ;
129
- const result = value || color ;
129
+ const result = value || this . color || '' ;
130
130
const hexString = Colors . getHexString ( result ) ;
131
131
this . props . onPress ?.( result , { tintColor, index, hexString} ) ;
132
132
} ;
@@ -141,11 +141,13 @@ class ColorSwatch extends PureComponent<Props & BaseComponentInjectedProps> {
141
141
}
142
142
143
143
getAccessibilityInfo ( ) {
144
- const color = this . color ;
145
-
144
+ const color = this . color || DEFAULT_COLOR ;
145
+ const defaultText = ! this . color ? 'default' : '' ;
146
+
146
147
return {
147
- accessibilityLabel : color && Colors . getColorName ( color ) ,
148
- accessibilityStates : this . props . selected ? [ 'selected' ] : [ ]
148
+ accessible : true ,
149
+ accessibilityLabel : `${ defaultText } color ${ Colors . getColorName ( color ) } ` ,
150
+ accessibilityState : { selected : this . props . selected }
149
151
} ;
150
152
}
151
153
@@ -159,11 +161,9 @@ class ColorSwatch extends PureComponent<Props & BaseComponentInjectedProps> {
159
161
160
162
renderContent ( ) {
161
163
const { style, onPress, unavailable, size = DEFAULT_SIZE , ...others } = this . props ;
162
- const color = this . color ;
163
164
const { isSelected} = this . state ;
164
165
const Container = onPress ? TouchableOpacity : View ;
165
- const tintColor = this . getTintColor ( color ) ;
166
- const accessibilityInfo = Constants . accessibility . isScreenReaderEnabled && this . getAccessibilityInfo ( ) ;
166
+ const tintColor = this . getTintColor ( this . color ) ;
167
167
168
168
return (
169
169
< Container
@@ -175,9 +175,9 @@ class ColorSwatch extends PureComponent<Props & BaseComponentInjectedProps> {
175
175
onPress = { this . onPress }
176
176
style = { [ this . styles . container , { width : size , height : size , borderRadius : size / 2 } , style ] }
177
177
onLayout = { this . onLayout }
178
- { ...accessibilityInfo }
178
+ { ...this . getAccessibilityInfo ( ) }
179
179
>
180
- { Colors . isTransparent ( color ) && (
180
+ { Colors . isTransparent ( this . color ) && (
181
181
< Image source = { transparentImage } style = { this . styles . transparentImage } resizeMode = { 'cover' } />
182
182
) }
183
183
{ unavailable ? (
@@ -222,11 +222,11 @@ class ColorSwatch extends PureComponent<Props & BaseComponentInjectedProps> {
222
222
223
223
export default asBaseComponent < ColorSwatchProps > ( ColorSwatch ) ;
224
224
225
- function createStyles ( { color = Colors . grey30 } ) {
225
+ function createStyles ( { color = DEFAULT_COLOR } ) {
226
226
return StyleSheet . create ( {
227
227
container : {
228
228
backgroundColor : color ,
229
- borderWidth : color === 'transparent' ? undefined : 1 ,
229
+ borderWidth : Colors . isTransparent ( color ) ? undefined : 1 ,
230
230
borderColor : Colors . rgba ( Colors . $outlineDisabledHeavy , 0.2 ) ,
231
231
margin : SWATCH_MARGIN ,
232
232
overflow : 'hidden'
0 commit comments