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

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 (129) hide show
  1. package/README.md +124 -2
  2. package/android/build.gradle +8 -1
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +53 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
  5. package/android/src/main/jni/CMakeLists.txt +38 -0
  6. package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
  8. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
  9. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
  10. package/ios/NanoIconInlineBaseline.h +4 -0
  11. package/ios/NanoIconInlineBaseline.mm +190 -0
  12. package/ios/NanoIconView.h +1 -0
  13. package/ios/NanoIconView.mm +118 -107
  14. package/lib/commonjs/cli/build.d.ts +5 -0
  15. package/lib/commonjs/cli/build.js +37 -15
  16. package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
  17. package/lib/commonjs/cli/buildSymbols.js +134 -0
  18. package/lib/commonjs/cli/config.d.ts +3 -1
  19. package/lib/commonjs/cli/config.js +3 -3
  20. package/lib/commonjs/cli/expoConfig.d.ts +3 -0
  21. package/lib/commonjs/cli/expoConfig.js +17 -6
  22. package/lib/commonjs/cli/index.d.ts +4 -2
  23. package/lib/commonjs/cli/index.js +12 -1
  24. package/lib/commonjs/cli/link.d.ts +15 -0
  25. package/lib/commonjs/cli/link.js +185 -1
  26. package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
  27. package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
  28. package/lib/commonjs/metro/index.d.ts +35 -0
  29. package/lib/commonjs/metro/index.js +92 -0
  30. package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
  31. package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
  32. package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
  33. package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
  34. package/lib/commonjs/plugin/src/index.d.ts +1 -1
  35. package/lib/commonjs/plugin/src/index.js +9 -3
  36. package/lib/commonjs/plugin/src/types.d.ts +34 -2
  37. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
  38. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
  39. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
  40. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
  41. package/lib/commonjs/scripts/cli.js +27 -9
  42. package/lib/commonjs/src/core/font/compile.js +3 -5
  43. package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
  44. package/lib/commonjs/src/core/font/quadratic.js +2 -0
  45. package/lib/commonjs/src/core/glyph/merge.js +3 -1
  46. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -0
  47. package/lib/commonjs/src/core/pathkit/contours.d.ts +1 -0
  48. package/lib/commonjs/src/core/pathkit/contours.js +18 -0
  49. package/lib/commonjs/src/core/pathkit/evenodd.js +1 -15
  50. package/lib/commonjs/src/core/pathkit/winding.d.ts +4 -0
  51. package/lib/commonjs/src/core/pathkit/winding.js +59 -0
  52. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  53. package/lib/commonjs/src/core/pipeline/config.js +6 -0
  54. package/lib/commonjs/src/core/pipeline/iconPool.d.ts +13 -2
  55. package/lib/commonjs/src/core/pipeline/iconPool.js +89 -31
  56. package/lib/commonjs/src/core/pipeline/index.d.ts +2 -0
  57. package/lib/commonjs/src/core/pipeline/index.js +3 -1
  58. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -0
  59. package/lib/commonjs/src/core/pipeline/prepare.js +18 -0
  60. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +3 -0
  61. package/lib/commonjs/src/core/pipeline/prepareIcon.js +11 -8
  62. package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
  63. package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
  64. package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
  65. package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -0
  66. package/lib/commonjs/src/core/pipeline/prepareWorker.js +3 -3
  67. package/lib/commonjs/src/core/pipeline/preparedSvgCache.d.ts +6 -0
  68. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
  69. package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +5 -0
  70. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +10 -8
  71. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
  72. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
  73. package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
  74. package/lib/commonjs/src/core/symbols/contents.js +15 -0
  75. package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
  76. package/lib/commonjs/src/core/symbols/knockout.js +51 -0
  77. package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
  78. package/lib/commonjs/src/core/symbols/layers.js +182 -0
  79. package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
  80. package/lib/commonjs/src/core/symbols/template.js +140 -0
  81. package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
  82. package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
  83. package/lib/commonjs/src/utils/fingerPrint.d.ts +11 -0
  84. package/lib/commonjs/src/utils/fingerPrint.js +28 -9
  85. package/lib/commonjs/src/utils/naming.d.ts +10 -0
  86. package/lib/commonjs/src/utils/naming.js +49 -0
  87. package/lib/module/createNanoIconsSet.native.js +29 -26
  88. package/lib/module/createNanoIconsSet.shared.js +3 -2
  89. package/lib/module/createNanoIconsSet.web.js +17 -5
  90. package/lib/module/devServerFont.js +30 -0
  91. package/lib/module/devServerFont.web.js +25 -0
  92. package/lib/module/loadDynamicFont.js +6 -3
  93. package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
  94. package/lib/module/symbols/index.android.js +42 -0
  95. package/lib/module/symbols/index.ios.js +35 -0
  96. package/lib/module/symbols/index.js +35 -0
  97. package/lib/module/symbols/index.native.js +12 -0
  98. package/lib/module/symbols/types.js +1 -0
  99. package/lib/module/utils/fingerPrint.js +18 -3
  100. package/lib/module/utils/glyphRuntime.js +36 -2
  101. package/lib/module/utils/naming.js +46 -0
  102. package/lib/module/utils/validateLayerColor.js +24 -0
  103. package/lib/typescript/src/core/glyph/parse.d.ts +1 -0
  104. package/lib/typescript/src/core/pathkit/contours.d.ts +1 -0
  105. package/lib/typescript/src/core/pathkit/winding.d.ts +5 -0
  106. package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
  107. package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
  108. package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
  109. package/lib/typescript/src/core/symbols/template.d.ts +23 -0
  110. package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
  111. package/lib/typescript/src/devServerFont.d.ts +4 -0
  112. package/lib/typescript/src/devServerFont.web.d.ts +4 -0
  113. package/lib/typescript/src/loadDynamicFont.d.ts +1 -0
  114. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +6 -5
  115. package/lib/typescript/src/symbols/index.android.d.ts +33 -0
  116. package/lib/typescript/src/symbols/index.d.ts +31 -0
  117. package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
  118. package/lib/typescript/src/symbols/index.native.d.ts +8 -0
  119. package/lib/typescript/src/symbols/types.d.ts +24 -0
  120. package/lib/typescript/src/types.d.ts +2 -0
  121. package/lib/typescript/src/utils/fingerPrint.d.ts +11 -0
  122. package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
  123. package/lib/typescript/src/utils/naming.d.ts +11 -0
  124. package/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
  125. package/metro.js +1 -0
  126. package/package.json +26 -2
  127. package/react-native-nano-icons.podspec +4 -1
  128. package/react-native.config.js +10 -0
  129. package/src/specs/NanoIconViewNativeComponent.ts +9 -6
package/README.md CHANGED
@@ -40,6 +40,7 @@ That’s it 🔬⚡️
40
40
  - [🧩 Platforms Supported](#-platforms-supported)
41
41
  - [🚀 Quick Start](#-quick-start)
42
42
  - [🎨 Multicolor Icons](#-multicolor-icons)
43
+ - [🧭 Native Symbol Support](#-native-symbol-support)
43
44
  - [📊 Performance](#-performance)
44
45
  - [⚠️ Known Limitations](#%EF%B8%8F-known-limitations)
45
46
  - [🔧 Font Generation Pipeline](#-font-generation-pipeline)
@@ -165,6 +166,28 @@ Bare apps don't have a prebuild step, so you run the same pipeline via the CLI:
165
166
  > [!TIP]
166
167
  > Run `EXPO_DEBUG=1 npx expo prebuild` or `npx react-native-nano-icons --verbose` to get font build-time logs.
167
168
 
169
+ ### 4. Add the Metro plugin (recommended)
170
+
171
+ Add the plugin to your Metro config to get hot reload for your icons: edit an SVG and the running dev app picks up the new glyph, with no native rebuild or CLI run.
172
+
173
+ ```js
174
+ // metro.config.js
175
+ const { getDefaultConfig } = require('expo/metro-config');
176
+ // or require('@react-native/metro-config') by React Native Community
177
+ const { withNanoIcons } = require('react-native-nano-icons/metro');
178
+
179
+ const config = getDefaultConfig(__dirname);
180
+
181
+ // Your modifications to the config
182
+
183
+ module.exports = withNanoIcons(config);
184
+ ```
185
+
186
+ Production builds are not affected — the fonts are linked exactly as configured, static or dynamic. The plugin uses the config from the steps above to speed up development process and experience.
187
+
188
+ > [!NOTE]
189
+ > Hot reload needs a development build; Expo Go cannot register fonts at runtime. Before a web export, run the font step as usual (CLI or `expo prebuild`).
190
+
168
191
  > [!NOTE]
169
192
  > In [Expo Go](https://expo.dev/go), icons are rendered using a regular `<Text>` fallback so you can iterate quickly. You will need to link the font manually via the already included [`expo-font` library](https://docs.expo.dev/versions/latest/sdk/font/), keyed by `glyphMap.m.f`. [Once you move to a development build](https://docs.expo.dev/develop/development-builds/expo-go-to-dev-build/), the library automatically switches to the native component implementation. Remember to remove any `expo-font`-related icon font setup after the switch.
170
193
 
@@ -174,7 +197,7 @@ Bare apps don't have a prebuild step, so you run the same pipeline via the CLI:
174
197
  > config.resolver.assetExts.push("woff2");
175
198
  > ```
176
199
 
177
- ### 4. Use
200
+ ### 5. Use
178
201
 
179
202
  ```TypeScript
180
203
  import { View, Text } from 'react-native'
@@ -205,6 +228,7 @@ export default function App() {
205
228
  | `name` | `string` | **(required)** | Icon name — corresponds to the original SVG filename. Fully typed from the glyphmap. |
206
229
  | `size` | `number` | `12` | Icon size in points. |
207
230
  | `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. |
231
+ | `tintMode` | `'all' \| 'currentColor'` | `'all'` | Which layers `color` applies to: every layer, or only those annotated with `currentColor` (an icon without any keeps its original colors). |
208
232
  | `allowFontScaling` | `boolean` | `true` | Whether the icon size respects the system accessibility font scale. |
209
233
  | `style` | `ViewStyle` | — | Style applied to the icon container. |
210
234
  | `accessible` | `boolean` | — | Override the default accessibility behavior. |
@@ -251,7 +275,7 @@ export const Icon = createNanoIconSet(glyphMap, require("./dynamic-ota-icons.ttf
251
275
 
252
276
  > If a dynamic glyphmap gets no font, its icons render blank until one is registered under `glyphMap.m.f` (with a dev warning).
253
277
 
254
- ### 5. Font Regeneration
278
+ ### 6. Font Regeneration
255
279
 
256
280
  **The build script detects changes in path and contents of the SVGs** in your input directory, in the set's config (`upm`, `safeZone`, `startUnicode`) and in the library version or the versions of the packages it builds fonts with, based on a fingerprint hash. If anything changes (file names, SVG attributes/nodes, config, an upgrade of `react-native-nano-icons` or of a font-building dependency) or the output font/glyphmap files are deleted, the icon set is regenerated during `prebuild` or manual script run. The first 8 characters of the fingerprint become part of the runtime font family (`glyphMap.m.f`), so a rebuilt set never clashes with a previous build that is still bundled in the app.
257
281
 
@@ -328,7 +352,10 @@ This makes the library well-suited for multicolor icons like country flags, bran
328
352
 
329
353
  - **Single string** — applies to all layers.
330
354
  - **Array** — each element maps to a layer. If the array is shorter than the number of layers, the last color is repeated.
355
+ - **`tintMode="currentColor"`** — `color` applies only to layers annotated with `currentColor` in the SVG, 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.
331
356
  - **Omitted** — uses the original SVG colors stored in the glyphmap.
357
+ - **Platform colors** — `PlatformColor(...)` and `DynamicColorIOS(...)` work in both forms and follow system appearance changes natively, without a re-render.
358
+ - **Invalid colors** — an unparseable color string falls back to black. In development an error names the icon and layer.
332
359
 
333
360
  An SVG with many distinct colors (e.g., a detailed vector image with 50 colors) produces at least 50 glyph layers. Each layer is a lightweight text glyph, so this is fine for typical icons (3–10 colors). For highly complex illustrations with dozens of colors, consider using `expo-image` instead.
334
361
 
@@ -339,6 +366,101 @@ Since all of that is actually simple text, you can use your beautiful multicolor
339
366
 
340
367
  ---
341
368
 
369
+ ## 🧭 Native Symbol Support
370
+
371
+ Native tab bars draw their icons themselves, so they can't host a React component like `<Icon>`. For them, the same SVGs are forged into native assets loaded by name: custom symbols in your iOS `Images.xcassets` and Android `VectorDrawable`s. `nativeNanoSymbol('home')` then returns an icon react-navigation accepts wherever it takes an `Icon`.
372
+
373
+ > [!NOTE]
374
+ > Native symbols are **iOS and Android only** and need `react-native-screens` 4.29+ with react-navigation 8. They are always bundled natively, so [dynamic linking](#dynamic-linking-expo-ota-updates-support) is not available for them.
375
+
376
+ ### 1. Configure
377
+
378
+ Add a `symbolSets` array next to `iconSets` in your `.nanoicons.json` (or the Expo plugin options):
379
+
380
+ ```JSON
381
+ {
382
+ "symbolSets": [{ "inputDir": "./assets/tabicons" }]
383
+ }
384
+ ```
385
+
386
+ <details>
387
+ <summary><u>All symbolSets Entry Options</u></summary>
388
+
389
+ | Property | Type | Required | Default | Description |
390
+ | :----------- | :-------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------- |
391
+ | `inputDir` | `string` | **Yes** | — | Path to the directory containing your `.svg` files. |
392
+ | `name` | `string` | No | Folder name | Set name, used for output filenames and the generated typed manifest. |
393
+ | `prefix` | `string` | No | `nano` | Symbol-name prefix: `home.svg` → `nano.home` (iOS) / `nano_home` (Android). |
394
+ | `outputDir` | `string` | No | `../nanoicons` | Path where the generated artifacts are written. Defaults to a sibling `nanoicons` folder. |
395
+
396
+ </details>
397
+
398
+ ### 2. Build and link
399
+
400
+ The same [build / prebuild step](#3-configure) that generates your fonts forges and links the symbols. Then rebuild the native app: symbols are compiled into the binary, so new or changed SVGs show up only after a native rebuild.
401
+
402
+ <details>
403
+ <summary><u>What gets generated</u></summary>
404
+
405
+ - **iOS** – one `<prefix>.<name>.symbolset` per SVG in your app's `Images.xcassets`.
406
+ - **Android** – two drawables per SVG in `res/drawable/`: `<prefix>_<name>` (monochrome) and `<prefix>_<name>_original`.
407
+ - **`outputDir`** – `<set>.symbols.d.ts`, a typed manifest that makes `nativeNanoSymbol` names (and react-navigation's `SFSymbolNames`) type-check from your filenames. Make sure your `tsconfig` includes it.
408
+
409
+ </details>
410
+
411
+ ### 3. Use
412
+
413
+ Return `nativeNanoSymbol(filename)` from any react-navigation icon option. Every symbol has two looks: `monochrome` (a silhouette in the bar's tint, the default) and `original` (the SVG's own colors).
414
+
415
+ ```TypeScript
416
+ import { nativeNanoSymbol } from 'react-native-nano-icons/symbols';
417
+
418
+ // monochrome — painted in the bar's tint
419
+ tabBarIcon: () => nativeNanoSymbol('message'),
420
+
421
+ // original — the icon's own colors while focused, the bar's tint while not
422
+ tabBarIcon: ({ focused }) =>
423
+ nativeNanoSymbol('flag-us', focused ? 'original' : 'monochrome'),
424
+ ```
425
+
426
+ <details>
427
+ <summary><u><code>nativeNanoSymbol(name, renderingMode?, prefix?)</code> Arguments</u></summary>
428
+
429
+ - `name` — the SVG filename.
430
+ - `renderingMode` — `'monochrome'` (default) or `'original'`. Returned as the symbol's `renderingMode` on iOS and as `tinted` on the Android image icon.
431
+ - `prefix` — matches the set's `prefix` (defaults to `nano`).
432
+
433
+ </details>
434
+
435
+ <details>
436
+ <summary><u>Icon turns into a solid block when tinted? (knockouts)</u></summary>
437
+
438
+ Tinting paints every shape in one color, so "white on color" art (lettering on a plate, stripes on a flag) would collapse into a solid block. Such details become **knockouts**: in `monochrome` they are holes that show the bar through the plate; in `original` they are painted in their own fill. By default every white (or near-white) shape over other shapes is a knockout. To choose them yourself, add `data-nano-knockout="true"` to the shapes or groups in the SVG; once an icon has an annotation, only annotated shapes are knockouts. A knockout floating over nothing is drawn in both modes.
439
+
440
+ ```xml
441
+ <svg viewBox="0 0 24 24">
442
+ <rect width="24" height="24" fill="#B22234"/>
443
+ <path data-nano-knockout="true" fill="#FFD700" d="…"/> <!-- hole when tinted, gold in color -->
444
+ </svg>
445
+ ```
446
+
447
+ </details>
448
+
449
+ <details>
450
+ <summary><u>Using symbols with <code>&lt;SFSymbol&gt;</code> (iOS)</u></summary>
451
+
452
+ Forged symbols also work in react-navigation's `<SFSymbol>` component and in `{ type: 'sfSymbol', name: 'nano.home' }`, including symbol effects. Palette and hierarchical rendering show a single color, because forged symbols only define monochrome and multicolor layers.
453
+
454
+ ```TypeScript
455
+ import { SFSymbol } from '@react-navigation/native';
456
+
457
+ <SFSymbol name="nano.folder" size={32} color="#001A72" effect={{ type: 'bounce', repeat: 'continuous' }} />
458
+ ```
459
+
460
+ </details>
461
+
462
+ ---
463
+
342
464
  ## 📊 Performance
343
465
 
344
466
  Native text engines are among the most optimized rendering pipelines in any OS. Rendering a glyph from a `.ttf` is synchronous and memory-efficient — unlike SVG, which requires XML parsing, native view tree creation, and Yoga layout calculation per icon instance.
@@ -5,7 +5,14 @@ buildscript {
5
5
  }
6
6
 
7
7
  apply plugin: 'com.android.library'
8
- apply plugin: 'org.jetbrains.kotlin.android'
8
+ // AGP 9 ships built-in Kotlin support and registers the `kotlin` extension
9
+ // itself. Applying the Kotlin plugin on top of it fails configuration with
10
+ // "Cannot add extension with name 'kotlin'". Only apply it when nothing has
11
+ // registered that extension yet.
12
+ if (project.extensions.findByName('kotlin') == null) {
13
+ apply plugin: 'org.jetbrains.kotlin.android'
14
+ }
15
+
9
16
  apply plugin: 'com.facebook.react'
10
17
 
11
18
  android {
@@ -1,10 +1,13 @@
1
1
  package com.nanoicons
2
2
 
3
3
  import android.content.Context
4
+ import android.content.res.Configuration
4
5
  import android.graphics.Canvas
6
+ import android.graphics.Color
5
7
  import android.graphics.Paint
6
8
  import android.graphics.Typeface
7
9
  import android.view.View
10
+ import com.facebook.react.bridge.ColorPropConverter
8
11
 
9
12
  class NanoIconView(context: Context) : View(context) {
10
13
 
@@ -12,6 +15,13 @@ class NanoIconView(context: Context) : View(context) {
12
15
  private val fontMetrics = Paint.FontMetrics()
13
16
  private var codepoints: IntArray = intArrayOf()
14
17
  private var colors: IntArray = intArrayOf()
18
+ // Unresolved layer colors: literal ARGB, plus resource paths for the entries that
19
+ // depend on the theme (PlatformColor). Kept so they can be re-resolved on a
20
+ // configuration change — the props are not re-sent for that.
21
+ private var literalColors: IntArray = intArrayOf()
22
+ private var colorPaths: Array<Array<String>?>? = null
23
+ private var tintColor: Int? = null
24
+ private var tintLayers: IntArray = intArrayOf()
15
25
  private var cachedFontFamily: String? = null
16
26
  private var cachedTypeface: Typeface? = null
17
27
  // Cached String objects — rebuilt only when codepoints change
@@ -64,8 +74,48 @@ class NanoIconView(context: Context) : View(context) {
64
74
  invalidate()
65
75
  }
66
76
 
67
- fun setColors(values: IntArray) {
68
- colors = values
77
+ fun setColors(literals: IntArray, paths: Array<Array<String>?>?) {
78
+ literalColors = literals
79
+ colorPaths = paths
80
+ resolveColors()
81
+ invalidate()
82
+ }
83
+
84
+ fun setTintColor(color: Int?) {
85
+ tintColor = color
86
+ invalidate()
87
+ }
88
+
89
+ fun setTintLayers(layers: IntArray) {
90
+ tintLayers = layers
91
+ invalidate()
92
+ }
93
+
94
+ private fun layerColor(index: Int): Int {
95
+ val tint = tintColor
96
+ if (tint != null && tintLayers.contains(index)) return tint
97
+ return if (index < colors.size) colors[index] else 0xFF000000.toInt()
98
+ }
99
+
100
+ // Resolve theme-dependent entries against this view's current context; literal
101
+ // entries pass through untouched.
102
+ private fun resolveColors() {
103
+ val paths = colorPaths
104
+ if (paths == null) {
105
+ colors = literalColors
106
+ return
107
+ }
108
+ colors = IntArray(literalColors.size) { i ->
109
+ val entry = paths[i] ?: return@IntArray literalColors[i]
110
+ entry.firstNotNullOfOrNull { ColorPropConverter.resolveResourcePath(context, it) }
111
+ ?: Color.BLACK
112
+ }
113
+ }
114
+
115
+ override fun onConfigurationChanged(newConfig: Configuration) {
116
+ super.onConfigurationChanged(newConfig)
117
+ if (colorPaths == null) return
118
+ resolveColors()
69
119
  invalidate()
70
120
  }
71
121
 
@@ -103,8 +153,7 @@ class NanoIconView(context: Context) : View(context) {
103
153
 
104
154
  // All layers drawn at the same position (stacked on each other)
105
155
  for (i in cachedTexts.indices) {
106
- val color = if (i < colors.size) colors[i] else 0xFF000000.toInt()
107
- paint.color = color
156
+ paint.color = layerColor(i)
108
157
  canvas.drawText(cachedTexts[i], 0f, cachedBaseline, paint)
109
158
  }
110
159
 
@@ -1,6 +1,9 @@
1
1
  package com.nanoicons
2
2
 
3
+ import android.graphics.Color
4
+ import com.facebook.react.bridge.ColorPropConverter
3
5
  import com.facebook.react.bridge.ReadableArray
6
+ import com.facebook.react.bridge.ReadableType
4
7
  import com.facebook.react.module.annotations.ReactModule
5
8
  import com.facebook.react.uimanager.SimpleViewManager
6
9
  import com.facebook.react.uimanager.ThemedReactContext
@@ -46,39 +49,60 @@ class NanoIconViewManager :
46
49
  }
47
50
  }
48
51
 
52
+ // Plain colors arrive pre-processed as ints; PlatformColor as a map. Resource-path
53
+ // maps are forwarded unresolved so the view can re-resolve them when the theme
54
+ // changes — resolving here would discard what that needs.
49
55
  @ReactProp(name = "colors")
50
56
  override fun setColors(view: NanoIconView, value: ReadableArray?) {
51
57
  if (value != null) {
52
- val arr = IntArray(value.size())
53
- for (i in 0 until value.size()) {
54
- arr[i] = value.getInt(i)
58
+ val size = value.size()
59
+ val literals = IntArray(size)
60
+ var paths: Array<Array<String>?>? = null
61
+ for (i in 0 until size) {
62
+ if (value.getType(i) == ReadableType.Map) {
63
+ val map = value.getMap(i)
64
+ val resourcePaths = map?.getArray("resource_paths")
65
+ if (resourcePaths != null) {
66
+ if (paths == null) paths = arrayOfNulls(size)
67
+ paths[i] =
68
+ Array(resourcePaths.size()) { resourcePaths.getString(it).orEmpty() }
69
+ } else {
70
+ // {space,r,g,b,a} wide-gamut form — theme-invariant, resolve once.
71
+ literals[i] = ColorPropConverter.getColor(map, view.context, Color.BLACK)
72
+ }
73
+ } else {
74
+ literals[i] = value.getInt(i)
75
+ }
55
76
  }
56
- view.setColors(arr)
77
+ view.setColors(literals, paths)
57
78
  }
58
79
  }
59
80
 
60
- @ReactProp(name = "fontSize", defaultFloat = 12f)
61
- override fun setFontSize(view: NanoIconView, value: Float) {
81
+ @ReactProp(name = "color", customType = "Color")
82
+ override fun setColor(view: NanoIconView, value: Int?) {
83
+ view.setTintColor(value)
84
+ }
85
+
86
+ @ReactProp(name = "tintLayers")
87
+ override fun setTintLayers(view: NanoIconView, value: ReadableArray?) {
88
+ val arr = if (value == null) intArrayOf() else IntArray(value.size()) { value.getInt(it) }
89
+ view.setTintLayers(arr)
90
+ }
91
+
92
+ @ReactProp(name = "size", defaultFloat = 12f)
93
+ override fun setSize(view: NanoIconView, value: Float) {
62
94
  view.setFontSize(value)
63
95
  }
64
96
 
97
+ @ReactProp(name = "allowFontScaling", defaultBoolean = true)
98
+ override fun setAllowFontScaling(view: NanoIconView, value: Boolean) {
99
+ }
100
+
65
101
  @ReactProp(name = "advanceWidth", defaultInt = 0)
66
102
  override fun setAdvanceWidth(view: NanoIconView, value: Int) {
67
- // Used for sizing on JS side; native view uses Canvas layout
68
103
  }
69
104
 
70
105
  @ReactProp(name = "unitsPerEm", defaultInt = 0)
71
106
  override fun setUnitsPerEm(view: NanoIconView, value: Int) {
72
- // Used for sizing on JS side; native view uses Canvas layout
73
- }
74
-
75
- @ReactProp(name = "iconWidth", defaultFloat = 0f)
76
- override fun setIconWidth(view: NanoIconView, value: Float) {
77
- // Width set via style from JS
78
- }
79
-
80
- @ReactProp(name = "iconHeight", defaultFloat = 0f)
81
- override fun setIconHeight(view: NanoIconView, value: Float) {
82
- // Height set via style from JS
83
107
  }
84
108
  }
@@ -0,0 +1,38 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE on)
3
+
4
+ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
5
+ set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../common/cpp)
6
+ set(LIB_COMMON_COMPONENTS_DIR ${LIB_COMMON_DIR}/react/renderer/components/RNNanoIconsSpec)
7
+ set(LIB_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
8
+ set(LIB_GENERATED_COMPONENTS_DIR ${LIB_GENERATED_JNI_DIR}/react/renderer/components/RNNanoIconsSpec)
9
+
10
+ file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS
11
+ ${LIB_GENERATED_JNI_DIR}/*.cpp
12
+ ${LIB_GENERATED_COMPONENTS_DIR}/*.cpp
13
+ ${LIB_COMMON_COMPONENTS_DIR}/*.cpp
14
+ )
15
+
16
+ add_library(
17
+ react_codegen_RNNanoIconsSpec
18
+ OBJECT
19
+ ${react_codegen_SRCS}
20
+ )
21
+
22
+ target_include_directories(
23
+ react_codegen_RNNanoIconsSpec
24
+ PUBLIC
25
+ .
26
+ ${LIB_COMMON_DIR}
27
+ ${LIB_GENERATED_JNI_DIR}
28
+ ${LIB_GENERATED_COMPONENTS_DIR}
29
+ )
30
+
31
+ target_link_libraries(
32
+ react_codegen_RNNanoIconsSpec
33
+ fbjni
34
+ jsi
35
+ reactnative
36
+ )
37
+
38
+ target_compile_reactnative_options(react_codegen_RNNanoIconsSpec PRIVATE)
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/JavaTurboModule.h>
4
+ #include <ReactCommon/TurboModule.h>
5
+ #include <jsi/jsi.h>
6
+
7
+ #include <react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h>
8
+
9
+ namespace facebook::react {
10
+
11
+ class JSI_EXPORT NativeNanoIconsFontLoaderSpecJSI : public JavaTurboModule {
12
+ public:
13
+ NativeNanoIconsFontLoaderSpecJSI(const JavaTurboModule::InitParams &params);
14
+ };
15
+
16
+ JSI_EXPORT
17
+ std::shared_ptr<TurboModule> RNNanoIconsSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
18
+
19
+ } // namespace facebook::react
@@ -0,0 +1,11 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h>
4
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
5
+
6
+ namespace facebook::react {
7
+
8
+ using NanoIconViewComponentDescriptor =
9
+ ConcreteComponentDescriptor<NanoIconViewShadowNode>;
10
+
11
+ } // namespace facebook::react
@@ -0,0 +1,46 @@
1
+ #include "NanoIconViewShadowNode.h"
2
+
3
+ #include <react/renderer/core/LayoutConstraints.h>
4
+ #include <react/renderer/core/LayoutContext.h>
5
+
6
+ namespace facebook::react {
7
+
8
+ extern const char NanoIconViewComponentName[] = "NanoIconView";
9
+
10
+ Size NanoIconViewShadowNode::measureContent(
11
+ const LayoutContext &layoutContext,
12
+ const LayoutConstraints &layoutConstraints) const {
13
+ const auto &props = getConcreteProps();
14
+ const Float height =
15
+ props.size * (props.allowFontScaling ? layoutContext.fontSizeMultiplier : 1);
16
+ const Float width = props.unitsPerEm > 0
17
+ ? height * static_cast<Float>(props.advanceWidth) / static_cast<Float>(props.unitsPerEm)
18
+ : height;
19
+ return layoutConstraints.clamp({width, height});
20
+ }
21
+
22
+ bool NanoIconViewShadowNode::shouldNewRevisionDirtyMeasurement(
23
+ const ShadowNode & /*sourceShadowNode*/,
24
+ const ShadowNodeFragment & /*fragment*/) const {
25
+ return false;
26
+ }
27
+
28
+ void NanoIconViewShadowNode::completeClone(
29
+ const ShadowNode &sourceShadowNode,
30
+ const ShadowNodeFragment &fragment) {
31
+ ConcreteViewShadowNode::completeClone(sourceShadowNode, fragment);
32
+ if (fragment.props == nullptr) {
33
+ return;
34
+ }
35
+ const auto &oldProps =
36
+ static_cast<const NanoIconViewProps &>(*sourceShadowNode.getProps());
37
+ const auto &newProps = getConcreteProps();
38
+ if (oldProps.size != newProps.size ||
39
+ oldProps.allowFontScaling != newProps.allowFontScaling ||
40
+ oldProps.advanceWidth != newProps.advanceWidth ||
41
+ oldProps.unitsPerEm != newProps.unitsPerEm) {
42
+ dirtyLayout();
43
+ }
44
+ }
45
+
46
+ } // namespace facebook::react
@@ -0,0 +1,41 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/RNNanoIconsSpec/EventEmitters.h>
4
+ #include <react/renderer/components/RNNanoIconsSpec/Props.h>
5
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
6
+ #include <jsi/jsi.h>
7
+
8
+ namespace facebook::react {
9
+
10
+ JSI_EXPORT extern const char NanoIconViewComponentName[];
11
+
12
+ class JSI_EXPORT NanoIconViewShadowNode final
13
+ : public ConcreteViewShadowNode<
14
+ NanoIconViewComponentName,
15
+ NanoIconViewProps,
16
+ NanoIconViewEventEmitter> {
17
+ public:
18
+ using ConcreteViewShadowNode::ConcreteViewShadowNode;
19
+
20
+ static ShadowNodeTraits BaseTraits() {
21
+ auto traits = ConcreteViewShadowNode::BaseTraits();
22
+ traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
23
+ traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
24
+ return traits;
25
+ }
26
+
27
+ Size measureContent(
28
+ const LayoutContext &layoutContext,
29
+ const LayoutConstraints &layoutConstraints) const override;
30
+
31
+ void completeClone(
32
+ const ShadowNode &sourceShadowNode,
33
+ const ShadowNodeFragment &fragment) override;
34
+
35
+ protected:
36
+ bool shouldNewRevisionDirtyMeasurement(
37
+ const ShadowNode &sourceShadowNode,
38
+ const ShadowNodeFragment &fragment) const override;
39
+ };
40
+
41
+ } // namespace facebook::react
@@ -0,0 +1,4 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ UIView *NanoIconParagraphNeedingBaselineCorrection(UIView *view);
4
+ CGFloat NanoIconInlineBaselineOffset(UIView *view, UIView *paragraph);