@@ -44,6 +44,16 @@ const faAcorn = {
44
44
}
45
45
46
46
47
+ // react-native-svg>9.x changed the way it uses the `fill` attribute. In earlier versions,
48
+ // it used an array ([0, DECIMAL_COLOR]), whereas newer versions dropped the array
49
+ // in favor of a scalar value %DECIMAL_COLOR%
50
+ function getActualFillColorHex ( element ) {
51
+ const fillProp = element . props . fill
52
+ const decimalColor = Array . isArray ( fillProp ) ? fillProp [ 1 ] : fillProp ;
53
+ // convert to hex
54
+ return decimalColor . toString ( 16 ) ;
55
+ }
56
+
47
57
fontawesome . library . add ( faCoffee , faCircle )
48
58
49
59
test . skip ( 'renders with icon specified as array' , ( ) => {
@@ -237,7 +247,7 @@ describe('duotone support', () => {
237
247
const tree = renderer . create ( < FontAwesomeIcon icon = { faAcorn } style = { styles . icon } /> ) . toJSON ( )
238
248
const primaryLayer = tree . children [ 0 ] . children [ 0 ] . children [ 1 ]
239
249
const secondaryLayer = tree . children [ 0 ] . children [ 0 ] . children [ 0 ]
240
- expect ( primaryLayer . props . fill [ 1 ] . toString ( 16 ) ) . toEqual ( 'ff0000ff' )
250
+ expect ( getActualFillColorHex ( primaryLayer ) ) . toEqual ( 'ff0000ff' )
241
251
expect ( secondaryLayer . props . fillOpacity ) . toEqual ( 0.4 )
242
252
} )
243
253
} )
@@ -251,7 +261,7 @@ describe('duotone support', () => {
251
261
const tree = renderer . create ( < FontAwesomeIcon icon = { faAcorn } style = { styles . icon } secondaryOpacity = { 0.123 } /> ) . toJSON ( )
252
262
const primaryLayer = tree . children [ 0 ] . children [ 0 ] . children [ 1 ]
253
263
const secondaryLayer = tree . children [ 0 ] . children [ 0 ] . children [ 0 ]
254
- expect ( primaryLayer . props . fill [ 1 ] . toString ( 16 ) ) . toEqual ( 'ff0000ff' )
264
+ expect ( getActualFillColorHex ( primaryLayer ) ) . toEqual ( 'ff0000ff' )
255
265
expect ( secondaryLayer . props . fillOpacity ) . toEqual ( 0.123 )
256
266
} )
257
267
} )
@@ -264,7 +274,7 @@ describe('duotone support', () => {
264
274
} )
265
275
const tree = renderer . create ( < FontAwesomeIcon icon = { faAcorn } style = { styles . icon } secondaryColor = { "red" } /> ) . toJSON ( )
266
276
const secondaryLayer = tree . children [ 0 ] . children [ 0 ] . children [ 0 ]
267
- expect ( secondaryLayer . props . fill [ 1 ] . toString ( 16 ) ) . toEqual ( 'ffff0000' )
277
+ expect ( getActualFillColorHex ( secondaryLayer ) ) . toEqual ( 'ffff0000' )
268
278
expect ( secondaryLayer . props . fillOpacity ) . toEqual ( 1 )
269
279
} )
270
280
} )
@@ -277,7 +287,7 @@ describe('duotone support', () => {
277
287
} )
278
288
const tree = renderer . create ( < FontAwesomeIcon icon = { faAcorn } style = { styles . icon } secondaryColor = { "red" } secondaryOpacity = { 0.123 } /> ) . toJSON ( )
279
289
const secondaryLayer = tree . children [ 0 ] . children [ 0 ] . children [ 0 ]
280
- expect ( secondaryLayer . props . fill [ 1 ] . toString ( 16 ) ) . toEqual ( 'ffff0000' )
290
+ expect ( getActualFillColorHex ( secondaryLayer ) ) . toEqual ( 'ffff0000' )
281
291
expect ( secondaryLayer . props . fillOpacity ) . toEqual ( 0.123 )
282
292
} )
283
293
} )
0 commit comments