Skip to content

Commit b8941f0

Browse files
authored
docs: add note about transformers like react-native-svg-transformer (#362)
1 parent b92c42b commit b8941f0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/docs/docs/guides/usage-with-react-navigation.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,39 @@ Function that given `{ focused: boolean }` returns `ImageSource` or `AppleIcon`
244244
SF Symbols are only supported on Apple platforms.
245245
:::
246246

247+
:::warning
248+
249+
Metro transformers that modify the import resolutions of images to something that is *not* React Native's `ImageSource` will break this. A notable community example of such is [react-native-svg-transformer](https://github.com/kristerkari/react-native-svg-transformer).
250+
251+
For best results, avoid the use of such transformers altogether.
252+
253+
If however, it is necessary to use such a transformer, you can modify your `metro.config.js` file to resolve the asset to `ImageSource` with another extension.
254+
255+
For example, with `react-native-svg-transformer`, you can resolve the `svg` extension to use `react-native-svg-transformer`, and use an alternative extension like `svgx` to resolve it normally with React Native's default behavior.
256+
257+
To do so, change the extension of your icon SVG file from `.svg` to `.svgx` and modify your `metro.config.js` file like so:
258+
259+
```diff
260+
config.transformer.babelTransformerPath = require.resolve(
261+
"react-native-svg-transformer"
262+
);
263+
config.resolver.assetExts = config.resolver.assetExts.filter(
264+
(ext) => ext !== "svg"
265+
);
266+
267+
+ config.resolver.assetExts = [...config.resolver.assetExts, "svgx"];
268+
269+
config.resolver.sourceExts = [...config.resolver.sourceExts, "svg"];
270+
```
271+
272+
Then change your require calls like so:
273+
```
274+
tabBarIcon: () => require('person.svgx')
275+
```
276+
277+
:::
278+
279+
247280
#### `tabBarBadge`
248281

249282
Badge to show on the tab icon.

0 commit comments

Comments
 (0)