Skip to content

Commit 0256bc0

Browse files
kimakgregberge
authored andcommitted
feat: allow Mask & Image on React Native (#202)
1 parent e6772d7 commit 0256bc0

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

packages/core/src/h2x/__snapshots__/toReactNative.test.js.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
exports[`toReactNative should take svg and convert it to react-native 1`] = `
44
"<Svg>
5-
<G stroke=\\"#063855\\" strokeWidth={2}>
6-
<Path d=\\"M51,37 L37,51\\" id=\\"Shape\\" />
7-
</G>
5+
<Defs>
6+
<Mask id=\\"mask1\\" x={0} y={0} width={100} height={100}>
7+
<Rect x={0} y={0} width={100} height={50} style={{\\"stroke\\":\\"none\\",\\"fill\\":\\"#ffffff\\"}} />
8+
</Mask>
9+
</Defs>
10+
<Image xlinkHref=\\"firefox.jpg\\" x={0} y={0} height=\\"50px\\" width=\\"50px\\" />
11+
<Rect x={1} y={1} width={100} height={100} style={{\\"stroke\\":\\"none\\",\\"fill\\":\\"#0000ff\\",\\"mask\\":\\"url(#mask1)\\"}} />
812
</Svg>
913
"
1014
`;

packages/core/src/h2x/toReactNative.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const elementToComponent = {
1919
use: 'Use',
2020
defs: 'Defs',
2121
stop: 'Stop',
22+
mask: 'Mask',
23+
image: 'Image',
2224
}
2325

2426
const componentToElement = Object.keys(elementToComponent).reduce(

packages/core/src/h2x/toReactNative.test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ describe('toReactNative', () => {
77
const result = transform(
88
`
99
<svg>
10-
<g stroke="#063855" stroke-width="2">
11-
<path d="M51,37 L37,51" id="Shape"></path>
12-
</g>
13-
</svg>
10+
<defs>
11+
<mask id="mask1" x="0" y="0" width="100" height="100" >
12+
<rect x="0" y="0" width="100" height="50"
13+
style="stroke:none; fill: #ffffff"/>
14+
</mask>
15+
</defs>
16+
<image xlink:href="firefox.jpg" x="0" y="0" height="50px" width="50px"/>
17+
<rect x="1" y="1" width="100" height="100"
18+
style="stroke: none; fill: #0000ff; mask: url(#mask1)"/>
19+
</svg>
1420
`,
1521
{ plugins: [jsx, toReactNative()] },
1622
)

0 commit comments

Comments
 (0)