@@ -23,32 +23,55 @@ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.
23
23
24
24
function _arrayWithoutHoles ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = new Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } }
25
25
26
+ function _objectWithoutProperties ( source , excluded ) { if ( source == null ) return { } ; var target = _objectWithoutPropertiesLoose ( source , excluded ) ; var key , i ; if ( Object . getOwnPropertySymbols ) { var sourceSymbolKeys = Object . getOwnPropertySymbols ( source ) ; for ( i = 0 ; i < sourceSymbolKeys . length ; i ++ ) { key = sourceSymbolKeys [ i ] ; if ( excluded . indexOf ( key ) >= 0 ) continue ; if ( ! Object . prototype . propertyIsEnumerable . call ( source , key ) ) continue ; target [ key ] = source [ key ] ; } } return target ; }
27
+
28
+ function _objectWithoutPropertiesLoose ( source , excluded ) { if ( source == null ) return { } ; var target = { } ; var sourceKeys = Object . keys ( source ) ; var key , i ; for ( i = 0 ; i < sourceKeys . length ; i ++ ) { key = sourceKeys [ i ] ; if ( excluded . indexOf ( key ) >= 0 ) continue ; target [ key ] = source [ key ] ; } return target ; }
29
+
26
30
var svgObjectMap = {
27
31
"svg" : _reactNativeSvg . Svg ,
28
- "path" : _reactNativeSvg . Path
32
+ "path" : _reactNativeSvg . Path ,
33
+ "rect" : _reactNativeSvg . Rect ,
34
+ "defs" : _reactNativeSvg . Defs ,
35
+ "mask" : _reactNativeSvg . Mask ,
36
+ "g" : _reactNativeSvg . G ,
37
+ "clipPath" : _reactNativeSvg . ClipPath
29
38
} ;
30
39
31
40
function convert ( createElement , element ) {
32
41
var extraProps = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
33
42
43
+ // console.log(`DEBUG: in convert. element.tag = ${element.tag} and extraProps = `, extraProps)
44
+ // console.log(`DEBUG: in convert. element.attributes = `, element.attributes)
34
45
if ( typeof element === 'string' ) {
35
46
return element ;
36
47
}
37
48
38
- var children = ( element . children || [ ] ) . map ( convert . bind ( null , createElement ) ) ;
49
+ var children = ( element . children || [ ] ) . map ( function ( child ) {
50
+ return convert ( createElement , child , extraProps ) ;
51
+ } ) ;
39
52
var mixins = Object . keys ( element . attributes || { } ) . reduce ( function ( acc , key ) {
40
53
var val = element . attributes [ key ] ;
41
54
42
55
switch ( key ) {
43
56
case 'class' :
44
- case 'fill' :
45
57
case 'role' :
46
- case 'style' :
58
+ case 'style' : // TODO: when react-native-svg supports the style prop, there may be a better way to do this.
59
+ // In the meantime, we're manually peeling off specific style properties, namely color, and passing them down
60
+ // to children as a fill prop
61
+ // See: https://github.com/react-native-community/react-native-svg/commit/e7d0eb6df676d4f63f9eba7c0cf5ddd6c4c85fbe
62
+
47
63
case 'xmlns' :
48
64
delete element . attributes [ key ] ;
49
65
break ;
50
66
67
+ case 'fill' :
68
+ // TODO: probably want to keep fill, but just translate 'currentColor' to 'black'
69
+ // When react-native-svg supports currentColor, pass it through
70
+ acc . attrs [ key ] = val === 'currentColor' ? 'black' : val ;
71
+ break ;
72
+
51
73
default :
74
+ // console.log(`DEBUG: for element tag <${element.tag}>, setting prop key=val to ${key}=`, val)
52
75
if ( key . indexOf ( 'aria-' ) === 0 || key . indexOf ( 'data-' ) === 0 ) {
53
76
delete element . attributes [ key ] ;
54
77
} else {
@@ -61,7 +84,19 @@ function convert(createElement, element) {
61
84
} , {
62
85
attrs : { }
63
86
} ) ;
64
- return createElement . apply ( void 0 , [ svgObjectMap [ element . tag ] , _objectSpread ( { } , mixins . attrs , extraProps ) ] . concat ( _toConsumableArray ( children ) ) ) ;
87
+
88
+ var style = // get rid of this key
89
+ // store the result here
90
+ extraProps . style ,
91
+ modifiedExtraProps = _objectWithoutProperties ( extraProps , [ "style" ] ) ; // If a color was passed in as a style sheet on the style prop, set the fill attribute to its value
92
+
93
+
94
+ if ( extraProps . style && extraProps . style . color ) {
95
+ modifiedExtraProps [ 'fill' ] = extraProps . style . color ;
96
+ } // console.log(`DEBUG: while creating element with tag=${element.tag}, we have extraProps: `, extraProps )
97
+
98
+
99
+ return createElement . apply ( void 0 , [ svgObjectMap [ element . tag ] , _objectSpread ( { } , mixins . attrs , modifiedExtraProps ) ] . concat ( _toConsumableArray ( children ) ) ) ;
65
100
}
66
101
67
102
var _default = convert ;
0 commit comments