Skip to content

Commit 888d968

Browse files
committed
feat(native): log unsupported components
1 parent 7cd92c3 commit 888d968

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/cli/__snapshots__/index.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ exports[`cli --native 1`] = `
4545
"import React from \\"react\\";
4646
import Svg, { Path } from \\"react-native-svg\\";
4747
48+
// SVGR has dropped some elements not supported by react-native-svg: title
49+
4850
const One = props => (
4951
<Svg width={48} height={1} viewBox=\\"0 0 48 1\\" {...props}>
5052
<Path d=\\"M0 0h48v1H0z\\" fill=\\"#063855\\" fillRule=\\"evenodd\\" />

src/h2x/toReactNative.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ const toReactNative = () => ({
3030
const component = elementToComponent[path.node.name]
3131
if (component) {
3232
path.node.name = component
33-
state.reactNativeSvgReplacedComponents = state.reactNativeSvgReplacedComponents || new Set()
33+
state.reactNativeSvgReplacedComponents =
34+
state.reactNativeSvgReplacedComponents || new Set()
3435
state.reactNativeSvgReplacedComponents.add(component)
3536
return
3637
}
3738

3839
// Remove element if not supported
3940
if (!componentToElement[path.node.name]) {
4041
state.unsupportedComponents = state.unsupportedComponents || new Set()
41-
state.unsupportedComponents.add(component)
42+
state.unsupportedComponents.add(path.node.name)
4243
path.remove()
4344
}
4445
},

src/transforms/wrapIntoNativeComponent.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
const componentsToImport = components =>
1+
const componentsToList = components =>
22
[...components].filter(component => component !== 'Svg').join(', ')
33

4+
const logUnsupportedComponents = components => {
5+
if (!components.size) return ''
6+
return `
7+
// SVGR has dropped some elements not supported by react-native-svg: ${componentsToList(
8+
components,
9+
)}
10+
`
11+
}
12+
413
export default (opts = {}) => (code, state) => {
5-
const { reactNativeSvgReplacedComponents = new Set() } = state
14+
const {
15+
reactNativeSvgReplacedComponents = new Set(),
16+
unsupportedComponents = new Set(),
17+
} = state
618

719
return `import React from 'react'
8-
import Svg, { ${componentsToImport(
20+
import Svg, { ${componentsToList(
921
reactNativeSvgReplacedComponents,
1022
)} } from 'react-native-svg';
23+
${logUnsupportedComponents(unsupportedComponents)}
24+
1125
1226
const ${state.componentName} = (${opts.expandProps ? 'props' : ''}) => ${code}
1327

0 commit comments

Comments
 (0)