Skip to content

Commit 2d2169a

Browse files
authored
Document React Native Nano Icons (#1522)
1 parent 31320c6 commit 2d2169a

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

33.1 KB
Binary file not shown.
197 KB
Binary file not shown.

‎versioned_docs/version-8.x/icons.md‎

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ tabBarIcon: {
383383
}
384384
```
385385

386+
To generate custom SF Symbols from SVG files, see [React Native Nano Icons](#react-native-nano-icons).
387+
386388
## Material Symbols
387389

388390
Material Symbols is a library of over 2,500 glyphs designed to integrate well with Material Design on Android.
@@ -538,10 +540,74 @@ tabBarIcon: {
538540
}
539541
```
540542

541-
Here `icon_name` is the resource name without the file extension. On Android, this can refer to a bitmap drawable such as `res/drawable/icon_name.png` or a vector drawable such as `res/drawable/icon_name.xml`. On iOS, this can refer to an image in an asset catalog, such as an image set named `icon_name`.
543+
Here `icon_name` is the resource name without the file extension. On Android, this can refer to a bitmap drawable such as `res/drawable/icon_name.png` or a vector drawable such as `res/drawable/icon_name.xml`. On iOS, this can refer to an image in an asset catalog, such as an image set named `icon_name`. To generate vector drawables from SVG files, see [React Native Nano Icons](#react-native-nano-icons).
542544

543545
## Other sources
544546

547+
### [React Native Nano Icons](https://github.com/software-mansion-labs/react-native-nano-icons)
548+
549+
[React Native Nano Icons](https://nano-icons.swmansion.com/) provides a way to use custom SVG files as performant font-based icons.
550+
551+
To use it, install the `react-native-nano-icons` package, then follow the [quick start](https://github.com/software-mansion-labs/react-native-nano-icons#-quick-start) to set it up with your SVG icons.
552+
553+
Then you can use the icon by passing the name to the `nativeNanoSymbol` function:
554+
555+
```js
556+
import { nativeNanoSymbol } from 'react-native-nano-icons/symbols';
557+
558+
// ...
559+
560+
tabBarIcon: nativeNanoSymbol('newspaper'),
561+
```
562+
563+
Here, we use `newspaper` as the icon name, which is the filename `newspaper.svg` without extension.
564+
565+
It returns `{ type: 'sfSymbol', name: 'nano.newspaper' }` on iOS, and `{ type: 'image', source: { uri: 'nano_newspaper' } }` on Android, which resolves to a native vector drawable asset.
566+
567+
The second argument specifies how to color the symbol:
568+
569+
- `monochrome` (default): Single color, using the tint color.
570+
- `multicolor`: Uses the original colors of the SVG file.
571+
572+
For example, to show the colors only when the tab is focused:
573+
574+
```js
575+
tabBarIcon: ({ focused }) =>
576+
nativeNanoSymbol('microscope', focused ? 'multicolor' : 'monochrome'),
577+
```
578+
579+
<video
580+
playsInline
581+
autoPlay
582+
muted
583+
loop
584+
style={{ width: '400px', aspectRatio: 800 / 180 }}
585+
>
586+
<source src="/assets/icons/nano-icons-ios.mp4" />
587+
</video>
588+
589+
<video
590+
playsInline
591+
autoPlay
592+
muted
593+
loop
594+
style={{ width: '400px', aspectRatio: 800 / 202 }}
595+
>
596+
<source src="/assets/icons/nano-icons-android.mp4" />
597+
</video>
598+
599+
The generated symbols are named with the [prefix](https://github.com/software-mansion-labs/react-native-nano-icons#symbolsets-options) of the symbol set, `nano` by default, and are added to [`SFSymbolNames`](#custom-sf-symbol-names) automatically. They can also be rendered with the standalone `SFSymbol` component:
600+
601+
```js
602+
import { SFSymbol } from '@react-navigation/native';
603+
604+
function MyComponent() {
605+
return <SFSymbol name="nano.newspaper" size={24} />;
606+
}
607+
```
608+
609+
For more general usage, the library also provides a font-based `Icon` component, created with [`createNanoIconSet`](https://github.com/software-mansion-labs/react-native-nano-icons#createnanoiconset), to render the icons in your own components.
610+
545611
### [React Native Vector Icons](https://github.com/oblador/react-native-vector-icons)
546612

547613
The React Native Vector Icons library provides various sets of font icons. Font icons cannot be used directly in most native navigation components such as tab bars or headers. But they can be [rasterized into images](https://github.com/oblador/react-native-vector-icons?tab=readme-ov-file#usage-as-png-imagesource-object) and used with the `type: 'image'` option.

0 commit comments

Comments
 (0)