Skip to content

Commit

Permalink
feat: allow Mask & Image on React Native (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimak authored and gregberge committed Oct 5, 2018
1 parent e6772d7 commit 0256bc0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/h2x/__snapshots__/toReactNative.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

exports[`toReactNative should take svg and convert it to react-native 1`] = `
"<Svg>
<G stroke=\\"#063855\\" strokeWidth={2}>
<Path d=\\"M51,37 L37,51\\" id=\\"Shape\\" />
</G>
<Defs>
<Mask id=\\"mask1\\" x={0} y={0} width={100} height={100}>
<Rect x={0} y={0} width={100} height={50} style={{\\"stroke\\":\\"none\\",\\"fill\\":\\"#ffffff\\"}} />
</Mask>
</Defs>
<Image xlinkHref=\\"firefox.jpg\\" x={0} y={0} height=\\"50px\\" width=\\"50px\\" />
<Rect x={1} y={1} width={100} height={100} style={{\\"stroke\\":\\"none\\",\\"fill\\":\\"#0000ff\\",\\"mask\\":\\"url(#mask1)\\"}} />
</Svg>
"
`;
2 changes: 2 additions & 0 deletions packages/core/src/h2x/toReactNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const elementToComponent = {
use: 'Use',
defs: 'Defs',
stop: 'Stop',
mask: 'Mask',
image: 'Image',
}

const componentToElement = Object.keys(elementToComponent).reduce(
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/h2x/toReactNative.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ describe('toReactNative', () => {
const result = transform(
`
<svg>
<g stroke="#063855" stroke-width="2">
<path d="M51,37 L37,51" id="Shape"></path>
</g>
</svg>
<defs>
<mask id="mask1" x="0" y="0" width="100" height="100" >
<rect x="0" y="0" width="100" height="50"
style="stroke:none; fill: #ffffff"/>
</mask>
</defs>
<image xlink:href="firefox.jpg" x="0" y="0" height="50px" width="50px"/>
<rect x="1" y="1" width="100" height="100"
style="stroke: none; fill: #0000ff; mask: url(#mask1)"/>
</svg>
`,
{ plugins: [jsx, toReactNative()] },
)
Expand Down

1 comment on commit 0256bc0

@vercel
Copy link

@vercel vercel bot commented on 0256bc0 Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://svgr-ptizcomiqq.now.sh to the following alias.

Please sign in to comment.