react-native-nano-icons 1.0.0 → 1.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +137 -21
  2. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +9 -2
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
  6. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +122 -0
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +60 -0
  8. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +0 -39
  9. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +2 -16
  10. package/ios/NanoIconView.mm +17 -5
  11. package/ios/NanoIconsFontLoader.mm +5 -0
  12. package/lib/commonjs/cli/build.d.ts +26 -0
  13. package/lib/commonjs/cli/build.js +174 -64
  14. package/lib/commonjs/cli/buildSymbols.d.ts +17 -0
  15. package/lib/commonjs/cli/buildSymbols.js +103 -42
  16. package/lib/commonjs/cli/expoConfig.d.ts +10 -0
  17. package/lib/commonjs/cli/expoConfig.js +22 -7
  18. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  19. package/lib/commonjs/cli/fingerprint.js +36 -0
  20. package/lib/commonjs/cli/index.d.ts +2 -2
  21. package/lib/commonjs/cli/index.js +3 -1
  22. package/lib/commonjs/cli/link.d.ts +4 -0
  23. package/lib/commonjs/cli/link.js +25 -0
  24. package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
  25. package/lib/commonjs/cli/sameOutputs.js +45 -0
  26. package/lib/commonjs/index.node.js +1 -1
  27. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
  28. package/lib/commonjs/plugin/src/buildFonts.js +11 -3
  29. package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
  30. package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
  31. package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
  32. package/lib/commonjs/plugin/src/frozen.js +18 -0
  33. package/lib/commonjs/plugin/src/index.js +3 -3
  34. package/lib/commonjs/plugin/src/types.d.ts +10 -0
  35. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
  36. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
  37. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
  38. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
  39. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
  40. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
  41. package/lib/commonjs/scripts/cli.js +31 -2
  42. package/lib/commonjs/src/core/flatten/dom.js +40 -5
  43. package/lib/commonjs/src/core/flatten/element.js +2 -1
  44. package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
  45. package/lib/commonjs/src/core/font/compile.d.ts +0 -1
  46. package/lib/commonjs/src/core/font/compile.js +2 -8
  47. package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
  48. package/lib/commonjs/src/core/glyph/merge.js +27 -36
  49. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
  50. package/lib/commonjs/src/core/glyph/parse.js +31 -18
  51. package/lib/commonjs/src/core/pathkit/winding.d.ts +7 -1
  52. package/lib/commonjs/src/core/pathkit/winding.js +172 -0
  53. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  54. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  55. package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
  56. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  57. package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
  58. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
  59. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  60. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  61. package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
  62. package/lib/commonjs/src/utils/fingerPrint.js +3 -1
  63. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  64. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  65. package/lib/module/createNanoIconsSet.js +0 -1
  66. package/lib/module/createNanoIconsSet.native.js +26 -21
  67. package/lib/module/createNanoIconsSet.shared.js +32 -18
  68. package/lib/module/createNanoIconsSet.web.js +103 -61
  69. package/lib/module/devServerFont.js +1 -1
  70. package/lib/module/devServerFont.web.js +3 -5
  71. package/lib/module/fontIntegrity.js +20 -38
  72. package/lib/module/fontIntegrity.web.js +48 -0
  73. package/lib/module/fontIntegrityStore.js +65 -0
  74. package/lib/module/index.js +1 -1
  75. package/lib/module/index.node.js +1 -1
  76. package/lib/module/index.web.js +4 -0
  77. package/lib/module/loadDynamicFont.js +3 -15
  78. package/lib/module/specs/NanoIconViewNativeComponent.ts +3 -2
  79. package/lib/module/utils/fingerPrint.js +3 -2
  80. package/lib/module/utils/fontIdentity.js +2 -2
  81. package/lib/module/utils/fontScale.js +23 -0
  82. package/lib/module/utils/glyphRuntime.js +13 -0
  83. package/lib/module/utils/iconAccessibility.js +26 -0
  84. package/lib/module/utils/iconPropsEqual.js +27 -0
  85. package/lib/module/utils/webCss.js +26 -0
  86. package/lib/module/utils/webStyle.js +86 -0
  87. package/lib/module/webFont.js +33 -0
  88. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  89. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  90. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  91. package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
  92. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  93. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  94. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  95. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  96. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  97. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  98. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  99. package/lib/typescript/src/index.d.ts +2 -1
  100. package/lib/typescript/src/index.web.d.ts +5 -0
  101. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  102. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +3 -2
  103. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  104. package/lib/typescript/src/types.d.ts +37 -9
  105. package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
  106. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  107. package/lib/typescript/src/utils/fontScale.d.ts +2 -0
  108. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  109. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  110. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  111. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  112. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  113. package/lib/typescript/src/webFont.d.ts +6 -0
  114. package/package.json +19 -3
  115. package/src/const/codegenPrimitives.ts +3 -3
  116. package/src/specs/NanoIconViewNativeComponent.ts +3 -2
  117. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  118. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  119. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  120. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
package/README.md CHANGED
@@ -42,6 +42,7 @@ That’s it 🔬⚡️
42
42
  - [📚 Guides](#-multicolor-icons)
43
43
  - [🎨 Multicolor Icons](#-multicolor-icons)
44
44
  - [🧭 Native Symbols](#-native-symbols)
45
+ - [🌐 Web](#-web)
45
46
  - [☁️ OTA Updates & Dynamic Linking](#%EF%B8%8F-ota-updates--dynamic-linking)
46
47
  - [🔁 Rebuilds & Font Integrity](#-rebuilds--font-integrity)
47
48
  - [📖 Reference](#-reference)
@@ -50,8 +51,10 @@ That’s it 🔬⚡️
50
51
  - [`<Icon>`](#icon)
51
52
  - [`addFontIntegrityListener()`](#addfontintegritylistener)
52
53
  - [`getFontIntegrityIssues()`](#getfontintegrityissues)
54
+ - [`useFontIntegrityIssue()`](#usefontintegrityissue)
53
55
  - [`symbolSets` options](#symbolsets-options)
54
56
  - [`nativeNanoSymbol()`](#nativenanosymbol)
57
+ - [`nanoIconsFingerprintSources()`](#nanoiconsfingerprintsources)
55
58
  - [CLI](#cli)
56
59
  - [📊 Performance](#-performance)
57
60
  - [⚠️ Known Limitations](#%EF%B8%8F-known-limitations)
@@ -121,7 +124,7 @@ The library uses an Expo Config Plugin to hook into the prebuild phase. This aut
121
124
  }
122
125
  ```
123
126
 
124
- The plugin accepts an `iconSets` array, so one build can generate multiple distinct fonts. See [all `iconSets` options](#iconsets-options).
127
+ The plugin accepts an `iconSets` array, so one build can generate multiple distinct fonts. See [all `iconSets` options](#iconsets-options). In CI, prebuild fails on out-of-date generated files instead of regenerating them, see [`frozen`](#when-fonts-are-regenerated).
125
128
 
126
129
  Then run `npx expo prebuild` and rebuild the app once (e.g. `npx expo run:ios`). After that, the [Metro plugin](#4-add-the-metro-plugin) picks up SVG edits without a rebuild.
127
130
 
@@ -156,10 +159,7 @@ Bare apps don't have a prebuild step, so you run the same pipeline via the CLI:
156
159
  3. **Rebuild** – For iOS and Android, rebuild the native app once. On iOS, run `pod install` in `ios/` first. After that, the [Metro plugin](#4-add-the-metro-plugin) picks up SVG edits without a rebuild.
157
160
 
158
161
  > [!NOTE]
159
- > With `"web": true` on an icon set, the `my-icons` set also gets `assets/icons/nanoicons/my-icons.woff2` next to its `.ttf`. Link it on web like any regular font, named `my-icons`. If you want to `require()` it through Metro (e.g. with `expo-font`), add this to `metro.config.js`:
160
- > ```js
161
- > config.resolver.assetExts.push("woff2");
162
- > ```
162
+ > With `"web": true` on an icon set, the `my-icons` set also gets `assets/icons/nanoicons/my-icons.woff2` next to its `.ttf`. See [Web](#-web) for loading it.
163
163
 
164
164
  > [!TIP]
165
165
  > For detailed build logs, run `npx react-native-nano-icons --verbose`, or set `EXPO_DEBUG=1` before `npx expo prebuild` or before starting Metro.
@@ -210,6 +210,10 @@ export default function App() {
210
210
  }
211
211
  ```
212
212
 
213
+ Icons without an `accessibilityLabel` are decorative, so screen readers skip them. Give a standalone icon a label, e.g. `<Icon name="heart" accessibilityLabel="Save" />`, to have it read as an image.
214
+
215
+ An icon is `size` tall, and its width keeps the proportions of its SVG: an SVG twice as wide as it is tall gives an icon `2 × size` wide. To line up icons of different widths, e.g. in a list, give them `frame="square"`: each icon then takes a `size` × `size` box, with the glyph scaled to fit and centered.
216
+
213
217
  See [all `<Icon>` props](#props).
214
218
 
215
219
  > [!NOTE]
@@ -257,7 +261,7 @@ This makes the library well-suited for multicolor icons like country flags, bran
257
261
  - **Single string** — applies to all layers.
258
262
  - **Array** — each element maps to a layer. If the array is shorter than the number of layers, the last color is repeated.
259
263
  - **`tintMode="currentColor"`** — `color` applies only to layers drawn with `currentColor` in the SVG (e.g. `fill="currentColor"`), so hardcoded colors (flags, logos) are kept. An array maps onto those layers in order, with the last color repeated. An icon with no `currentColor` layers renders in its original colors.
260
- - **Omitted** — uses the original SVG colors stored in the glyphmap. `currentColor` layers render black on iOS and Android, and inherit the CSS text color on web.
264
+ - **Omitted** — uses the original SVG colors stored in the glyphmap. `currentColor` layers render black on iOS and Android. On web, an icon drawn only in black or `currentColor` follows the CSS text color.
261
265
  - **Platform colors** — `PlatformColor(...)` and `DynamicColorIOS(...)` work as a single color and inside an array, and follow system appearance changes natively, without a re-render.
262
266
  - **Invalid colors** — an unparseable color string falls back to black. In development an error names the icon and layer. Not checked in Expo Go or on web.
263
267
 
@@ -337,6 +341,45 @@ tabBarIcon: ({ focused }) =>
337
341
 
338
342
  ---
339
343
 
344
+ ## 🌐 Web
345
+
346
+ Icons work in Expo web, Next.js (also in Server Components) and other React apps, without `react-native-web`.
347
+
348
+ ### Loading the font
349
+
350
+ Set `"web": true` on the icon set and pass the URL of its `.woff2` to `createNanoIconSet`:
351
+
352
+ ```TypeScript
353
+ // Icon.web.ts
354
+ import { createNanoIconSet } from "react-native-nano-icons";
355
+ import glyphMap from "./assets/icons/nanoicons/my-icons.glyphmap.json";
356
+
357
+ export const Icon = createNanoIconSet(
358
+ glyphMap,
359
+ require("./assets/icons/nanoicons/my-icons.woff2")
360
+ );
361
+ ```
362
+
363
+ - **Expo:** `require()` gives the URL. Add `config.resolver.assetExts.push("woff2")` to `metro.config.js`.
364
+ - **Next.js:** set `"outputDir": "./public/nanoicons"` and pass `"/nanoicons/my-icons.woff2"`.
365
+
366
+ This works for static and dynamic sets. Keep it in a `.web.ts` file: on iOS and Android a static set ignores the font argument and warns. Icons stay empty until the font has loaded, instead of showing other characters. A font you load yourself, e.g. with `expo-font` or a stylesheet, works too when it is registered under `fontFamily`. A font that fails to load is reported as a [font integrity](#font-integrity-check) issue.
367
+
368
+ Server rendering needs React 19. With React 18, icons work in the browser only.
369
+
370
+ ### Styling with CSS
371
+
372
+ - **Size:** without `size`, an icon follows the CSS `font-size`. `size` sets it in px. With `frame="square"`, it is as wide as it is tall.
373
+ - **Color:** without `color`, an icon drawn only in black or `currentColor` follows the CSS `color`. Other icons keep their colors.
374
+ - **`className`:** any CSS class applies, e.g. Tailwind, and overrides the default size and color.
375
+ - **`style`:** React Native styles work, including style arrays and `transform`.
376
+
377
+ ```TypeScript
378
+ <Icon name="heart" className="text-2xl lg:text-4xl text-red-500" />
379
+ ```
380
+
381
+ ---
382
+
340
383
  ## ☁️ OTA Updates & Dynamic Linking
341
384
 
342
385
  TL;DR the default static linking is best for most use cases: it ships the font inside the app binary, ready at launch. If you have an [over-the-air (OTA) updates workflow](https://expo.dev/solutions/eas-ota-updates) and make changes to your icons frequently, you can opt out of native bundling and register a particular iconSet font at runtime explicitly.
@@ -399,6 +442,22 @@ npx react-native-nano-icons --dynamic
399
442
 
400
443
  The CLI rebuilds only the sets defined with `linking: "dynamic"`, and skips all native linking. Commit the updated `.ttf` and `.glyphmap.json` and push your OTA update as usual ☁️ 🚀
401
444
 
445
+ ### EAS Update fingerprint
446
+
447
+ With EAS Update's `fingerprint` runtime version policy, add your icon sets to the [app fingerprint](https://docs.expo.dev/versions/latest/sdk/fingerprint/) in a `fingerprint.config.js` next to your app config:
448
+
449
+ ```js
450
+ // fingerprint.config.js
451
+ const { nanoIconsFingerprintSources } = require('react-native-nano-icons/fingerprint');
452
+
453
+ /** @type {import('expo/fingerprint').Config} */
454
+ module.exports = {
455
+ extraSources: nanoIconsFingerprintSources(__dirname),
456
+ };
457
+ ```
458
+
459
+ The fingerprint then changes when the SVGs, options or library version of a static icon set or a symbol set change, so an update is not sent to binaries built with the old fonts. Dynamic sets are left out, because the update delivers them.
460
+
402
461
  ---
403
462
 
404
463
  ## 🔁 Rebuilds & Font Integrity
@@ -412,10 +471,20 @@ Running `npx expo prebuild` or the CLI regenerates an icon set when its SVGs or
412
471
  > - **Bare React Native** – run `npx react-native-nano-icons`. The [Metro plugin](#4-add-the-metro-plugin) sends rebuilt fonts to the running dev app, but it does not link them into the native project.
413
472
  > - **Expo** – EAS Build runs `npx expo prebuild` for you when `ios/` and `android/` are not committed. Otherwise, or without EAS, run `npx expo prebuild` yourself.
414
473
 
474
+ To fail CI when the committed files are out of date, run the CLI with `--check`. It names each set whose files a build would change or whose font copies in `ios/` and `android/` are out of date, and why, writes nothing, and exits with 1. When only the library or tool versions changed, it builds the set in a temp folder and compares, so an upgrade that builds the same files passes:
475
+
476
+ ```sh
477
+ npx react-native-nano-icons --check
478
+ ```
479
+
480
+ With Expo, prebuild in CI fails instead of regenerating out-of-date files, like a frozen lockfile install. It names each set and why. This applies when the `CI` environment variable is set and is not `false` or `0`, as on EAS Build, and only to sets whose generated files exist, e.g. are committed. Sets without generated files are built. To change it, set the plugin's `frozen` option: `true` checks every set, also outside CI, and `false` turns it off.
481
+
415
482
  ### Font integrity check
416
483
 
417
484
  Each glyphmap refers to the exact font it was built with. On iOS and Android, at startup the library checks, once per icon set, that this font is available. If it is missing or comes from a different build, the set's icons render blank. A warning is printed in development, and the issue is recorded in every build. Read recorded issues with [`addFontIntegrityListener()`](#addfontintegritylistener) and [`getFontIntegrityIssues()`](#getfontintegrityissues).
418
485
 
486
+ On web, an issue is recorded when the set's font fails to load, e.g. a 404 or a file that is not a font. This covers the font passed to `createNanoIconSet`, a font from your own CSS, and [`Icon.loadFont()`](#methods). A set with no font at all is not reported. Sets rendered only in React Server Components are not checked.
487
+
419
488
  **Example:** an OTA update changes icons in a set with `linking: 'static'`. The update delivers the new glyphmap, but the installed app still has the old font, so the check fails. Use `linking: 'dynamic'` for sets you update over the air: the update then delivers the font too. See [OTA Updates & Dynamic Linking](#%EF%B8%8F-ota-updates--dynamic-linking).
420
489
 
421
490
  Forward `"found"` issues to your error monitoring (e.g. Sentry) to catch a bad OTA update. A font registered another way, e.g. with `expo-font`, never resolves an issue.
@@ -430,6 +499,17 @@ addFontIntegrityListener((issue, status) => {
430
499
  });
431
500
  ```
432
501
 
502
+ In release builds, a static set is checked synchronously by `createNanoIconSet`, so `getFontIntegrityIssues()` already lists its issue before the first render. Dynamic sets, and static sets in development builds, where a missing font is first fetched from Metro, are checked asynchronously. To render a fallback when an issue is found, use [`useFontIntegrityIssue()`](#usefontintegrityissue):
503
+
504
+ ```tsx
505
+ import { useFontIntegrityIssue } from 'react-native-nano-icons';
506
+
507
+ function AppIcon(props: IconProps) {
508
+ const issue = useFontIntegrityIssue(glyphMap.m.f);
509
+ return issue ? <SvgIcon {...props} /> : <Icon {...props} />;
510
+ }
511
+ ```
512
+
433
513
  For every scenario and its message, see [FONT_INTEGRITY.md](https://github.com/software-mansion-labs/react-native-nano-icons/blob/main/packages/react-native-nano-icons/docs/FONT_INTEGRITY.md).
434
514
 
435
515
  ---
@@ -443,13 +523,14 @@ Each entry of `iconSets` (in the Expo plugin options or `.nanoicons.json`) gener
443
523
  | Property | Type | Required | Default | Description |
444
524
  | :------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------- |
445
525
  | `inputDir` | `string` | **Yes** | — | Path to the directory containing your `.svg` files (e.g., `./assets/icons/ui`), relative to the folder of `.nanoicons.json` or the app config. Subfolders are not read. |
446
- | `fontFamily` | `string` | No | Folder Name | The file name of the generated `.ttf` and `.glyphmap.json`. If omitted, the name of the `inputDir` folder is used (e.g., `ui`). On iOS and Android, the font family registered at runtime is `glyphMap.m.f`: this name plus a hash of the icons and build settings (e.g. `ui-1a2b3c4d`), so each change gets a new family. On web, the family is this name. |
526
+ | `fontFamily` | `string` | No | Folder Name | The file name of the generated `.ttf` and `.glyphmap.json`. If omitted, the name of the `inputDir` folder is used (e.g., `ui`). On iOS and Android, the font family registered at runtime is `glyphMap.m.f`: this name plus a hash of the built font (e.g. `ui-1a2b3c4d`), so each change to the font gets a new family. On web, you can also register the font yourself under this name. |
447
527
  | `outputDir` | `string` | No | Sibling `nanoicons` folder | Path where the `.ttf` and `.glyphmap.json` files are saved, relative to the folder of `.nanoicons.json` or the app config. Defaults to a `nanoicons` folder next to `inputDir`. |
448
528
  | `upm` | `number` | No | `1024` | Units Per Em. Defines the resolution of the font grid. |
449
529
  | `safeZone` | `number` | No | `upm` | Height, in font units, that each icon's `viewBox` is scaled to. The rest of the em square is padding. Must not exceed `upm`. |
530
+ | `curveTolerance` | `number` | No | `1/512` (≈ `0.002`) | How far a curve in the font may be from the curve in the SVG, as a fraction of the em (the `size` prop). Fonts store curves as quadratic Béziers, so cubic curves are approximated. At `size={512}` the default allows 1 px. Lower values store more points. |
450
531
  | `startUnicode` | `string \| number` | No | `0xe900` | The first Unicode codepoint for the icon glyphs. A string is parsed as hex (`"e900"` or `"0xe900"`). |
451
532
  | `linking` | `'static' \| 'dynamic'` | No | `'static'` | Delivery mode for the generated TTF. `'static'` bundles it into the native app. `'dynamic'` excludes it from native linking so the host app can deliver it at runtime (e.g. via an OTA update). See [OTA Updates & Dynamic Linking](#%EF%B8%8F-ota-updates--dynamic-linking). |
452
- | `web` | `boolean` | No | `false` | Also emit `<fontFamily>.woff2` into `outputDir`, rebuilt together with the `.ttf` on every change. It is never linked natively; link it on web like any other web font, under the family name `<fontFamily>`. |
533
+ | `web` | `boolean` | No | `false` | Also emit `<fontFamily>.woff2` into `outputDir`, rebuilt together with the `.ttf` on every change. It is never linked natively. On web, pass its URL to `createNanoIconSet`, see [Web](#-web). |
453
534
 
454
535
  <details>
455
536
  <summary>Default Dir Path Behavior</summary>
@@ -469,10 +550,18 @@ createNanoIconSet(glyphMap, font?)
469
550
  | Argument | Default | Description |
470
551
  | :--------- | :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
471
552
  | `glyphMap` | **(required)** | The generated `.glyphmap.json`. Icon names are typed from it. |
472
- | `font` | `undefined` | Font source for a set with `linking: 'dynamic'`: `require('./icons.ttf')`, `{ uri }`, or a path string. Ignored for static sets and on web. See [OTA Updates & Dynamic Linking](#%EF%B8%8F-ota-updates--dynamic-linking). |
553
+ | `font` | `undefined` | Font source for a set with `linking: 'dynamic'`: `require('./icons.ttf')`, `{ uri }`, or a path string. Ignored for static sets. See [OTA Updates & Dynamic Linking](#%EF%B8%8F-ota-updates--dynamic-linking). On web, the font URL for any set, see [Web](#-web). |
473
554
 
474
555
  Returns the [`<Icon>`](#icon) component.
475
556
 
557
+ The glyphmap types are exported as `NanoGlyphMap`, `NanoGlyphMapInput`, `GlyphEntry` and `GlyphLayer`:
558
+
559
+ ```TypeScript
560
+ import type { GlyphEntry } from 'react-native-nano-icons';
561
+
562
+ const [advanceWidth, layers] = glyphMap.i.heart as GlyphEntry;
563
+ ```
564
+
476
565
  ### `<Icon>`
477
566
 
478
567
  The component returned by [`createNanoIconSet()`](#createnanoiconset).
@@ -482,17 +571,18 @@ The component returned by [`createNanoIconSet()`](#createnanoiconset).
482
571
  | Prop | Type | Default | Description |
483
572
  | -------------------- | ---------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
484
573
  | `name` | `string` | **(required)** | Icon name — corresponds to the original SVG filename. Fully typed from the glyphmap. |
485
- | `size` | `number` | `12` | Icon size in points. |
574
+ | `size` | `number` | `12` | Icon size in points. On web the default is `1em`, so the icon follows the CSS `font-size`. |
486
575
  | `color` | `ColorValue \| ColorValue[]` | Glyphmap defaults | Single color applied to all layers, or per-layer color array. If the array is shorter than the number of layers, the last color is repeated. |
487
576
  | `tintMode` | `'all' \| 'currentColor'` | `'all'` | Which layers `color` applies to: every layer, or only those drawn with `currentColor` (an icon without any keeps its original colors). |
488
577
  | `allowFontScaling` | `boolean` | `true` | Whether the icon size respects the system accessibility font scale. |
489
- | `style` | `ViewStyle` | `undefined` | Style applied to the icon container. |
490
- | `className` | `string` | `undefined` | Web only. Forwarded to the container element. |
491
- | `accessible` | `boolean` | `undefined` | Override the default accessibility behavior. |
492
- | `accessibilityLabel` | `string` | Icon `name` | Label announced by screen readers. Defaults to the icon name. |
493
- | `accessibilityRole` | `AccessibilityRole` | `"image"` | Accessibility role. Defaults to `"image"` so the icon is not misinterpreted as text. |
494
- | `accessibilityElementsHidden` | `boolean` | `undefined` | iOS and web only. Hides the icon from screen readers. |
495
- | `importantForAccessibility` | `'auto' \| 'yes' \| 'no' \| 'no-hide-descendants'` | `undefined` | Android only. Controls whether screen readers reach the icon. |
578
+ | `frame` | `'fit-glyph' \| 'square'` | `'fit-glyph'` | The box the icon is drawn in. `'fit-glyph'`: `size` tall, with the width following the SVG's proportions. `'square'`: `size` tall and wide, with the glyph scaled to fit and centered, like `resizeMode="contain"`. |
579
+ | `style` | `StyleProp<ViewStyle>` | `undefined` | Style applied to the icon container. |
580
+ | `className` | `string` | `undefined` | Web only. CSS classes for the icon, e.g. Tailwind. |
581
+ | `accessible` | `boolean` | `false` without a label | Set `true` to expose an icon without a label to screen readers. `accessibilityRole`, `importantForAccessibility="yes"` and `accessibilityElementsHidden={false}` expose it too. On web, its label is then the icon `name`. |
582
+ | `accessibilityLabel` | `string` | `undefined` | Label announced by screen readers. Without it, the icon is decorative and hidden from screen readers. |
583
+ | `accessibilityRole` | `AccessibilityRole` | `"image"` with a label | Accessibility role. Defaults to `"image"` so the icon is not misinterpreted as text. |
584
+ | `accessibilityElementsHidden` | `boolean` | `true` without a label | iOS and web only. Hides the icon from screen readers. |
585
+ | `importantForAccessibility` | `'auto' \| 'yes' \| 'no' \| 'no-hide-descendants'` | `'no-hide-descendants'` without a label | Android only. Controls whether screen readers reach the icon. |
496
586
  | `testID` | `string` | `undefined` | Test identifier for e2e testing frameworks. |
497
587
  | `ref` | `Ref<View>` | `undefined` | Ref to the underlying native view. On web, the container `<span>`. |
498
588
 
@@ -506,7 +596,7 @@ Icon.loadFont(font?): Promise<void>
506
596
  | :------- | :--------------------------------------- | :------------------------------------------------------------------- |
507
597
  | `font` | The `font` passed to `createNanoIconSet` | Font source: `require('./icons.ttf')`, `{ uri }`, or a path string. |
508
598
 
509
- Registers a dynamic set's font again, for example to retry a failed remote load when the network comes back (e.g. in a [NetInfo](https://github.com/react-native-netinfo/react-native-netinfo) listener), or to load the font later. A successful load resolves the set's [font integrity](#font-integrity-check) issue. The promise rejects if the font cannot be loaded. For static sets and on web, it is a no-op.
599
+ Registers a dynamic set's font again, for example to retry a failed remote load when the network comes back (e.g. in a [NetInfo](https://github.com/react-native-netinfo/react-native-netinfo) listener), or to load the font later. A successful load resolves the set's [font integrity](#font-integrity-check) issue. The promise rejects if the font cannot be loaded. For static sets on iOS and Android, it is a no-op. On web, it registers the font under `fontFamily` for any set, and a failed load is recorded as an issue.
510
600
 
511
601
  ### `addFontIntegrityListener()`
512
602
 
@@ -521,7 +611,7 @@ addFontIntegrityListener(listener): () => void
521
611
  `status` is one of:
522
612
 
523
613
  - `"found"`: the set's font is missing or out of date, so its icons render blank. A listener added later receives the current issues immediately.
524
- - `"resolved"`: the library loaded a dynamic set's font after the issue was found, through the `createNanoIconSet` font argument or [`Icon.loadFont()`](#methods). Its icons render again, and the issue is removed from `getFontIntegrityIssues()`.
614
+ - `"resolved"`: the library loaded a dynamic set's font after the issue was found, through the `createNanoIconSet` font argument or [`Icon.loadFont()`](#methods). On web, a successful `Icon.loadFont()` resolves the issue of any set. Its icons render again, and the issue is removed from `getFontIntegrityIssues()`.
525
615
 
526
616
  Returns a function that removes the listener.
527
617
 
@@ -537,7 +627,19 @@ Returns the current issues. Each issue has:
537
627
  - `family`: the font family the glyphmap refers to (`glyphMap.m.f`).
538
628
  - `linking`: `'static'` or `'dynamic'`.
539
629
  - `message`: the warning text.
540
- - `cause`: the load error behind a dynamic font failure, when there is one.
630
+ - `cause`: the load error behind a dynamic font failure, or a web font load failure, when there is one.
631
+
632
+ ### `useFontIntegrityIssue()`
633
+
634
+ ```TypeScript
635
+ useFontIntegrityIssue(family: string): FontIntegrityIssue | undefined
636
+ ```
637
+
638
+ | Argument | Default | Description |
639
+ | :------- | :------------- | :--------------------------------------------------- |
640
+ | `family` | **(required)** | The font family the glyphmap refers to: `glyphMap.m.f`. |
641
+
642
+ Returns the set's current issue, with the [`getFontIntegrityIssues()`](#getfontintegrityissues) shape, or `undefined`. The component re-renders when an issue is found or resolved. During server rendering it returns `undefined`.
541
643
 
542
644
  ### `symbolSets` options
543
645
 
@@ -578,10 +680,22 @@ Returns a react-navigation `Icon`: `{ type: 'sfSymbol', name, renderingMode }` o
578
680
  >
579
681
  > For `'multicolor'`, use `{ type: 'sfSymbol', name: 'nano.home', renderingMode: 'multicolor' }` on iOS and `{ type: 'image', source: { uri: 'nano_home_original' }, tinted: false }` on Android.
580
682
 
683
+ ### `nanoIconsFingerprintSources()`
684
+
685
+ ```TypeScript
686
+ import { nanoIconsFingerprintSources } from 'react-native-nano-icons/fingerprint';
687
+
688
+ nanoIconsFingerprintSources(projectRoot: string): FingerprintSource[]
689
+ ```
690
+
691
+ Returns `extraSources` for `fingerprint.config.js`, read from the plugin options in the app config. `projectRoot` is the folder of the app config: pass `__dirname` from a `fingerprint.config.js` next to it.
692
+
693
+ Each icon set with `linking: 'static'` and each symbol set adds one source, a hash of its SVGs, its options and the installed library versions. Dynamic sets are left out. Returns no sources when the plugin is not configured, and warns and returns none when the sets can't be read. See [EAS Update fingerprint](#eas-update-fingerprint).
694
+
581
695
  ### CLI
582
696
 
583
697
  ```sh
584
- npx react-native-nano-icons [--path <dir|file>] [--verbose] [--dynamic] [--dynamic-app-config] [--help]
698
+ npx react-native-nano-icons [--path <dir|file>] [--verbose] [--dynamic] [--dynamic-app-config] [--check] [--help]
585
699
  ```
586
700
 
587
701
  | Flag | Description |
@@ -590,6 +704,7 @@ npx react-native-nano-icons [--path <dir|file>] [--verbose] [--dynamic] [--dynam
590
704
  | `--verbose` | Show per-SVG processing details and extra build and linking notes. |
591
705
  | `--dynamic` | Rebuild only icon sets with `linking: 'dynamic'` and skip native linking. See [Regenerating dynamic fonts only](#regenerating-dynamic-fonts-only). |
592
706
  | `--dynamic-app-config` | Like `--dynamic`, but reads the sets from the Expo app config (`app.json` / `app.config.js` / `app.config.ts`) instead of `.nanoicons.json`. |
707
+ | `--check` | Report the sets whose files a build would change or whose font copies in `ios/` and `android/` are out of date, with the reason, and exit with 1 if there are any. Writes and links nothing in the project. Checks the sets the same command without `--check` would build, so `--check --dynamic` checks only the dynamic sets. |
593
708
  | `-h`, `--help` | Print the usage and exit without building. |
594
709
 
595
710
  ---
@@ -668,6 +783,7 @@ This repository is a yarn workspaces monorepo containing the library package and
668
783
 
669
784
  - **Bare React Native app:** [`examples/BareReactNativeExample/`](https://github.com/software-mansion-labs/react-native-nano-icons/blob/main/examples/BareReactNativeExample/)
670
785
  - **Expo app:** [`examples/ExpoExample/`](https://github.com/software-mansion-labs/react-native-nano-icons/blob/main/examples/ExpoExample/)
786
+ - **Next.js app (web only):** [`examples/NextExample/`](https://github.com/software-mansion-labs/react-native-nano-icons/blob/main/examples/NextExample/)
671
787
  </details>
672
788
 
673
789
  #### Code of Conduct
@@ -6,10 +6,13 @@ import com.facebook.react.bridge.UiThreadUtil
6
6
  import com.facebook.react.common.assets.ReactFontManager
7
7
  import java.util.Collections
8
8
  import java.util.WeakHashMap
9
+ import java.util.concurrent.ConcurrentHashMap
9
10
 
10
11
  object NanoIconFonts {
11
12
  private val liveViews: MutableSet<NanoIconView> =
12
13
  Collections.newSetFromMap(WeakHashMap())
14
+ private val registered: MutableSet<String> = ConcurrentHashMap.newKeySet()
15
+ private val FONT_ASSET_EXTENSIONS = listOf(".ttf", ".otf")
13
16
 
14
17
  fun resolve(family: String, assets: AssetManager): Typeface? {
15
18
  val typeface =
@@ -18,12 +21,24 @@ object NanoIconFonts {
18
21
  return if (typeface == null || typeface == systemFallback) null else typeface
19
22
  }
20
23
 
24
+ fun isAvailable(family: String, assets: AssetManager): Boolean =
25
+ family in registered ||
26
+ FONT_ASSET_EXTENSIONS.any { isFontAsset(assets, "fonts/$family$it") }
27
+
28
+ private fun isFontAsset(assets: AssetManager, path: String): Boolean =
29
+ try {
30
+ Typeface.createFromAsset(assets, path) != Typeface.DEFAULT
31
+ } catch (e: RuntimeException) {
32
+ false
33
+ }
34
+
21
35
  fun track(view: NanoIconView) {
22
36
  liveViews.add(view)
23
37
  }
24
38
 
25
39
  fun register(family: String, typeface: Typeface) {
26
40
  ReactFontManager.getInstance().setTypeface(family, Typeface.NORMAL, typeface)
41
+ registered.add(family)
27
42
  UiThreadUtil.runOnUiThread {
28
43
  for (view in liveViews.toList()) view.resolveFontIfMissing()
29
44
  }
@@ -26,8 +26,11 @@ class NanoIconView(context: Context) : View(context) {
26
26
  private var cachedTypeface: Typeface? = null
27
27
  // Cached String objects — rebuilt only when codepoints change
28
28
  private var cachedTexts: Array<String> = emptyArray()
29
- // Cached baseline — rebuilt when font, size, or bounds change
29
+ // Cached baseline — rebuilt when font, size, bounds, or square glyph scale change
30
30
  private var cachedBaseline: Float = 0f
31
+ private var squareGlyphScale = 0f
32
+ private var advanceWidth = 0
33
+ private var unitsPerEm = 0
31
34
  // Derived from the loaded font's metrics; recomputed on typeface change.
32
35
  private var textSizeFactor = 0f
33
36
  private var baselineFactor = 0f
@@ -68,6 +71,20 @@ class NanoIconView(context: Context) : View(context) {
68
71
  invalidate()
69
72
  }
70
73
 
74
+ fun setSquareGlyphScale(value: Float) {
75
+ squareGlyphScale = value
76
+ fitToBounds()
77
+ invalidate()
78
+ }
79
+
80
+ fun setAdvanceWidth(value: Int) {
81
+ advanceWidth = value
82
+ }
83
+
84
+ fun setUnitsPerEm(value: Int) {
85
+ unitsPerEm = value
86
+ }
87
+
71
88
  fun setCodepoints(values: IntArray) {
72
89
  codepoints = values
73
90
  cachedTexts = Array(values.size) { i -> String(Character.toChars(values[i])) }
@@ -139,8 +156,9 @@ class NanoIconView(context: Context) : View(context) {
139
156
  private fun fitToBounds() {
140
157
  val h = height.toFloat()
141
158
  if (h <= 0f || textSizeFactor <= 0f) return
142
- cachedBaseline = h * baselineFactor
143
- val size = h * textSizeFactor
159
+ val glyphHeight = if (squareGlyphScale > 0f) minOf(width, height) * squareGlyphScale else h
160
+ cachedBaseline = (h - glyphHeight) / 2 + glyphHeight * baselineFactor
161
+ val size = glyphHeight * textSizeFactor
144
162
  if (paint.textSize != size) paint.textSize = size
145
163
  }
146
164
 
@@ -150,11 +168,16 @@ class NanoIconView(context: Context) : View(context) {
150
168
 
151
169
  canvas.save()
152
170
  canvas.clipRect(0f, 0f, width.toFloat(), height.toFloat())
171
+ val left = if (squareGlyphScale > 0f) {
172
+ (width - minOf(width, height) * squareGlyphScale * advanceWidth / unitsPerEm) / 2
173
+ } else {
174
+ 0f
175
+ }
153
176
 
154
177
  // All layers drawn at the same position (stacked on each other)
155
178
  for (i in cachedTexts.indices) {
156
179
  paint.color = layerColor(i)
157
- canvas.drawText(cachedTexts[i], 0f, cachedBaseline, paint)
180
+ canvas.drawText(cachedTexts[i], left, cachedBaseline, paint)
158
181
  }
159
182
 
160
183
  canvas.restore()
@@ -94,15 +94,22 @@ class NanoIconViewManager :
94
94
  view.setFontSize(value)
95
95
  }
96
96
 
97
- @ReactProp(name = "allowFontScaling", defaultBoolean = true)
98
- override fun setAllowFontScaling(view: NanoIconView, value: Boolean) {
97
+ @ReactProp(name = "fontScale", defaultFloat = 1f)
98
+ override fun setFontScale(view: NanoIconView, value: Float) {
99
99
  }
100
100
 
101
101
  @ReactProp(name = "advanceWidth", defaultInt = 0)
102
102
  override fun setAdvanceWidth(view: NanoIconView, value: Int) {
103
+ view.setAdvanceWidth(value)
103
104
  }
104
105
 
105
106
  @ReactProp(name = "unitsPerEm", defaultInt = 0)
106
107
  override fun setUnitsPerEm(view: NanoIconView, value: Int) {
108
+ view.setUnitsPerEm(value)
109
+ }
110
+
111
+ @ReactProp(name = "squareGlyphScale", defaultFloat = 0f)
112
+ override fun setSquareGlyphScale(view: NanoIconView, value: Float) {
113
+ view.setSquareGlyphScale(value)
107
114
  }
108
115
  }
@@ -65,6 +65,9 @@ class NanoIconsFontLoaderModule(reactContext: ReactApplicationContext) :
65
65
  }
66
66
  }
67
67
 
68
+ override fun isFontAvailable(family: String): Boolean =
69
+ NanoIconFonts.isAvailable(family, reactApplicationContext.assets)
70
+
68
71
  private fun openStream(uri: String): InputStream =
69
72
  when {
70
73
  uri.startsWith("content://") ->
@@ -0,0 +1,122 @@
1
+ #include "NanoIconProps.h"
2
+
3
+ #include <react/renderer/core/PropsMacros.h>
4
+ #include <react/renderer/core/propsConversions.h>
5
+ #include <yoga/style/StyleSizeLength.h>
6
+
7
+ namespace facebook::react {
8
+
9
+ namespace {
10
+
11
+ bool rawPropIsSet(const RawProps &rawProps, const char *name, bool sourceValue) {
12
+ const auto *rawValue = rawProps.at(name, nullptr, nullptr);
13
+ if (rawValue == nullptr) {
14
+ return sourceValue;
15
+ }
16
+ return rawValue->hasValue();
17
+ }
18
+
19
+ } // namespace
20
+
21
+ NanoIconProps::NanoIconProps(
22
+ const PropsParserContext &context,
23
+ const NanoIconProps &sourceProps,
24
+ const RawProps &rawProps)
25
+ : ViewProps(context, sourceProps, rawProps),
26
+ fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})),
27
+ codepoints(convertRawProp(context, rawProps, "codepoints", sourceProps.codepoints, {})),
28
+ colors(convertRawProp(context, rawProps, "colors", sourceProps.colors, {})),
29
+ color(convertRawProp(context, rawProps, "color", sourceProps.color, {})),
30
+ tintLayers(convertRawProp(context, rawProps, "tintLayers", sourceProps.tintLayers, {})),
31
+ size(convertRawProp(context, rawProps, "size", sourceProps.size, {0.0})),
32
+ fontScale(convertRawProp(context, rawProps, "fontScale", sourceProps.fontScale, {1.0})),
33
+ advanceWidth(convertRawProp(context, rawProps, "advanceWidth", sourceProps.advanceWidth, {0})),
34
+ unitsPerEm(convertRawProp(context, rawProps, "unitsPerEm", sourceProps.unitsPerEm, {0})),
35
+ squareGlyphScale(convertRawProp(context, rawProps, "squareGlyphScale", sourceProps.squareGlyphScale, {0.0})),
36
+ hasStyleWidth(rawPropIsSet(rawProps, "width", sourceProps.hasStyleWidth)),
37
+ hasStyleHeight(rawPropIsSet(rawProps, "height", sourceProps.hasStyleHeight)) {
38
+ applyGlyphDimensions();
39
+ }
40
+
41
+ void NanoIconProps::setProp(
42
+ const PropsParserContext &context,
43
+ RawPropsPropNameHash hash,
44
+ const char *propName,
45
+ const RawValue &value) {
46
+ ViewProps::setProp(context, hash, propName, value);
47
+ switch (hash) {
48
+ case CONSTEXPR_RAW_PROPS_KEY_HASH("width"):
49
+ hasStyleWidth = value.hasValue();
50
+ applyGlyphDimensions();
51
+ break;
52
+ case CONSTEXPR_RAW_PROPS_KEY_HASH("height"):
53
+ hasStyleHeight = value.hasValue();
54
+ applyGlyphDimensions();
55
+ break;
56
+ }
57
+ }
58
+
59
+ void NanoIconProps::applyGlyphDimensions() {
60
+ const Float height = size * fontScale;
61
+ const bool square = squareGlyphScale > 0;
62
+ const Float width = !square && unitsPerEm > 0
63
+ ? height * static_cast<Float>(advanceWidth) / static_cast<Float>(unitsPerEm)
64
+ : height;
65
+ if (!hasStyleWidth) {
66
+ yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(width));
67
+ }
68
+ if (!hasStyleHeight) {
69
+ yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(height));
70
+ }
71
+ }
72
+
73
+ #ifdef RN_SERIALIZABLE_STATE
74
+ ComponentName NanoIconProps::getDiffPropsImplementationTarget() const {
75
+ return "NanoIconView";
76
+ }
77
+
78
+ folly::dynamic NanoIconProps::getDiffProps(const Props *prevProps) const {
79
+ static const auto defaultProps = NanoIconProps();
80
+ const NanoIconProps *oldProps = prevProps == nullptr
81
+ ? &defaultProps
82
+ : static_cast<const NanoIconProps *>(prevProps);
83
+ if (this == oldProps) {
84
+ return folly::dynamic::object();
85
+ }
86
+ folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
87
+
88
+ if (fontFamily != oldProps->fontFamily) {
89
+ result["fontFamily"] = fontFamily;
90
+ }
91
+ if (codepoints != oldProps->codepoints) {
92
+ result["codepoints"] = toDynamic(codepoints);
93
+ }
94
+ if (colors != oldProps->colors) {
95
+ result["colors"] = toDynamic(colors);
96
+ }
97
+ if (color != oldProps->color) {
98
+ result["color"] = *color;
99
+ }
100
+ if (tintLayers != oldProps->tintLayers) {
101
+ result["tintLayers"] = toDynamic(tintLayers);
102
+ }
103
+ if ((size != oldProps->size) && !(std::isnan(size) && std::isnan(oldProps->size))) {
104
+ result["size"] = size;
105
+ }
106
+ if ((fontScale != oldProps->fontScale) && !(std::isnan(fontScale) && std::isnan(oldProps->fontScale))) {
107
+ result["fontScale"] = fontScale;
108
+ }
109
+ if (advanceWidth != oldProps->advanceWidth) {
110
+ result["advanceWidth"] = advanceWidth;
111
+ }
112
+ if (unitsPerEm != oldProps->unitsPerEm) {
113
+ result["unitsPerEm"] = unitsPerEm;
114
+ }
115
+ if ((squareGlyphScale != oldProps->squareGlyphScale) && !(std::isnan(squareGlyphScale) && std::isnan(oldProps->squareGlyphScale))) {
116
+ result["squareGlyphScale"] = squareGlyphScale;
117
+ }
118
+ return result;
119
+ }
120
+ #endif
121
+
122
+ } // namespace facebook::react
@@ -0,0 +1,60 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/view/ViewProps.h>
4
+ #include <react/renderer/core/PropsParserContext.h>
5
+ #include <react/renderer/graphics/Color.h>
6
+ #include <vector>
7
+
8
+ namespace facebook::react {
9
+
10
+ // Why this class exists instead of the codegen NanoIconViewProps.
11
+ // 1. The icon box must be an explicit width/height in the Yoga style. A parent
12
+ // row with the default alignItems: 'stretch' stretches every child to the
13
+ // row height unless the child has explicit dimensions; a measure function
14
+ // does not count, Yoga ignores it in the stretch pass.
15
+ // 2. Those dimensions must be stored on the Props object. On every update RN
16
+ // copies the style from Props onto the Yoga node, so values written to the
17
+ // node directly would be wiped and cause a re-layout each time.
18
+ // 3. The codegen class only parses what JS sent and is final, so it cannot be
19
+ // extended. This class repeats that parsing and adds one step: compute
20
+ // width and height from size, fontScale and the glyph advance ratio, or a
21
+ // square box when squareGlyphScale is set, and store them in the style
22
+ // unless the user style already sets them.
23
+ class NanoIconProps final : public ViewProps {
24
+ public:
25
+ NanoIconProps() = default;
26
+ NanoIconProps(
27
+ const PropsParserContext &context,
28
+ const NanoIconProps &sourceProps,
29
+ const RawProps &rawProps);
30
+
31
+ void setProp(
32
+ const PropsParserContext &context,
33
+ RawPropsPropNameHash hash,
34
+ const char *propName,
35
+ const RawValue &value);
36
+
37
+ std::string fontFamily{};
38
+ std::vector<int> codepoints{};
39
+ std::vector<SharedColor> colors{};
40
+ SharedColor color{};
41
+ std::vector<int> tintLayers{};
42
+ Float size{0.0};
43
+ Float fontScale{1.0};
44
+ int advanceWidth{0};
45
+ int unitsPerEm{0};
46
+ Float squareGlyphScale{0.0};
47
+ bool hasStyleWidth{false};
48
+ bool hasStyleHeight{false};
49
+
50
+ #ifdef RN_SERIALIZABLE_STATE
51
+ ComponentName getDiffPropsImplementationTarget() const override;
52
+
53
+ folly::dynamic getDiffProps(const Props *prevProps) const override;
54
+ #endif
55
+
56
+ private:
57
+ void applyGlyphDimensions();
58
+ };
59
+
60
+ } // namespace facebook::react