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
@@ -0,0 +1,190 @@
1
+ #import "NanoIconInlineBaseline.h"
2
+ #import "NanoIconView.h"
3
+ #import <React/RCTVersion.h>
4
+ #import <React/RCTViewComponentView.h>
5
+ #import <react/renderer/textlayoutmanager/RCTAttributedTextUtils.h>
6
+ #import <objc/runtime.h>
7
+ #import <vector>
8
+
9
+ // RN <= 0.81 puts an inline view's bottom exactly on the text baseline.
10
+ // Since 0.82 (facebook/react-native#53341) the frame is `line bottom + descender
11
+ // of the attachment run's font`, and that run only carries the NSTextStorage
12
+ // default font, so the view lands below the baseline by an amount that
13
+ // depends on the text's font size and lineHeight.
14
+ static BOOL NanoIconReactNativePlacesInlineViewsOffBaseline(void) {
15
+ static BOOL result;
16
+ static dispatch_once_t once;
17
+ dispatch_once(&once, ^{
18
+ NSDictionary *version = RCTGetReactNativeVersion();
19
+ NSInteger major = [version[RCTVersionMajor] integerValue];
20
+ NSInteger minor = [version[RCTVersionMinor] integerValue];
21
+ result = major > 0 || minor >= 82;
22
+ });
23
+ return result;
24
+ }
25
+
26
+ // The paragraph view is the direct superview of an inline icon; a couple of
27
+ // extra levels cover wrappers RN may insert. nil for standalone icons and on
28
+ // RN <= 0.81, so those never pay for a layout.
29
+ static void NanoIconInstallParagraphUpdateHook(Class paragraphClass);
30
+
31
+ UIView *NanoIconParagraphNeedingBaselineCorrection(UIView *view) {
32
+ if (!NanoIconReactNativePlacesInlineViewsOffBaseline()) return nil;
33
+ UIView *current = view.superview;
34
+ for (int depth = 0; depth < 3 && current; depth++) {
35
+ if ([NSStringFromClass([current class]) isEqualToString:@"RCTParagraphComponentView"]) {
36
+ NanoIconInstallParagraphUpdateHook([current class]);
37
+ return current;
38
+ }
39
+ current = current.superview;
40
+ }
41
+ return nil;
42
+ }
43
+
44
+ // Text is laid out inside the paragraph's content frame (bounds minus
45
+ // padding). RCTViewComponentView keeps it in a protected ivar.
46
+ static CGRect NanoIconContentFrame(UIView *paragraph) {
47
+ static Ivar ivar = class_getInstanceVariable([RCTViewComponentView class], "_layoutMetrics");
48
+ if (ivar) {
49
+ const auto &metrics = *reinterpret_cast<const facebook::react::LayoutMetrics *>(
50
+ reinterpret_cast<const uint8_t *>((__bridge const void *)paragraph) + ivar_getOffset(ivar));
51
+ facebook::react::Rect content = metrics.getContentFrame();
52
+ if (content.size.width > 0 && content.size.height > 0) {
53
+ return CGRectMake(content.origin.x, content.origin.y, content.size.width, content.size.height);
54
+ }
55
+ }
56
+ return paragraph.bounds;
57
+ }
58
+
59
+ @interface NanoIconParagraphBaselines : NSObject
60
+ @property (nonatomic, readonly) std::vector<CGPoint> &entries;
61
+ @end
62
+
63
+ @implementation NanoIconParagraphBaselines {
64
+ std::vector<CGPoint> _entries;
65
+ }
66
+ - (std::vector<CGPoint> &)entries { return _entries; }
67
+ @end
68
+
69
+ static const void *kNanoIconParagraphBaselinesKey = &kNanoIconParagraphBaselinesKey;
70
+
71
+ static void NanoIconInvalidateIconsIn(UIView *view, int depth) {
72
+ for (UIView *child in view.subviews) {
73
+ if ([child isKindOfClass:[NanoIconView class]]) {
74
+ [(NanoIconView *)child invalidateInlineBaseline];
75
+ } else if (depth > 1) {
76
+ NanoIconInvalidateIconsIn(child, depth - 1);
77
+ }
78
+ }
79
+ }
80
+
81
+ // A text change that keeps an icon's frame (same line bottom, different font
82
+ // or lineHeight) still moves the baseline, and RN only notifies children whose
83
+ // layout changed. The paragraph's state update is the one signal that covers
84
+ // every text change, so its icons are invalidated from there.
85
+ static void NanoIconInstallParagraphUpdateHook(Class paragraphClass) {
86
+ static dispatch_once_t once;
87
+ dispatch_once(&once, ^{
88
+ SEL selector = @selector(updateState:oldState:);
89
+ Method method = class_getInstanceMethod(paragraphClass, selector);
90
+ if (!method) return;
91
+ using StateRef = const facebook::react::State::Shared &;
92
+ auto original = reinterpret_cast<void (*)(id, SEL, StateRef, StateRef)>(method_getImplementation(method));
93
+ IMP hooked = imp_implementationWithBlock(^(UIView *paragraph, StateRef state, StateRef oldState) {
94
+ original(paragraph, selector, state, oldState);
95
+ objc_setAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
96
+ NanoIconInvalidateIconsIn(paragraph, 3);
97
+ });
98
+ method_setImplementation(method, hooked);
99
+ });
100
+ }
101
+
102
+ // Lays the paragraph out again the way RCTTextLayoutManager does (same
103
+ // container settings and lineHeight baseline offset) and records where TextKit
104
+ // put the baseline of every attachment. Layout stops after the last attachment.
105
+ static NanoIconParagraphBaselines *NanoIconLayOutBaselines(UIView *paragraph, NSAttributedString *text) {
106
+ CGRect content = NanoIconContentFrame(paragraph);
107
+ NSTextContainer *container = [[NSTextContainer alloc] initWithSize:content.size];
108
+ container.lineFragmentPadding = 0;
109
+ container.lineBreakMode = NSLineBreakByClipping;
110
+ NSLayoutManager *layoutManager = [NSLayoutManager new];
111
+ layoutManager.usesFontLeading = NO;
112
+ [layoutManager addTextContainer:container];
113
+ NSTextStorage *storage = [[NSTextStorage alloc] initWithAttributedString:text];
114
+ RCTApplyBaselineOffset(storage);
115
+ [storage addLayoutManager:layoutManager];
116
+
117
+ __block NSUInteger lastAttachmentEnd = 0;
118
+ [storage enumerateAttribute:NSAttachmentAttributeName
119
+ inRange:NSMakeRange(0, storage.length)
120
+ options:0
121
+ usingBlock:^(NSTextAttachment *attachment, NSRange range, __unused BOOL *stop) {
122
+ if (attachment) lastAttachmentEnd = NSMaxRange(range);
123
+ }];
124
+ if (lastAttachmentEnd == 0) return nil;
125
+ [layoutManager ensureLayoutForCharacterRange:NSMakeRange(0, lastAttachmentEnd)];
126
+
127
+ NanoIconParagraphBaselines *baselines = [NanoIconParagraphBaselines new];
128
+ std::vector<CGPoint> &entries = baselines.entries;
129
+ [storage enumerateAttribute:NSAttachmentAttributeName
130
+ inRange:NSMakeRange(0, lastAttachmentEnd)
131
+ options:0
132
+ usingBlock:^(NSTextAttachment *attachment, NSRange range, __unused BOOL *stop) {
133
+ if (!attachment) return;
134
+ NSUInteger glyphIndex = [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:NULL].location;
135
+ CGRect line = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex effectiveRange:NULL];
136
+ CGPoint location = [layoutManager locationForGlyphAtIndex:glyphIndex];
137
+ entries.push_back(CGPointMake(content.origin.x + location.x,
138
+ content.origin.y + line.origin.y + location.y));
139
+ }];
140
+ return baselines;
141
+ }
142
+
143
+ // One layout per paragraph per layout pass: the result is kept on the
144
+ // paragraph view until the next main-queue turn so sibling icons reuse it.
145
+ static NanoIconParagraphBaselines *NanoIconBaselinesForParagraph(UIView *paragraph) {
146
+ NanoIconParagraphBaselines *cached = objc_getAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey);
147
+ if (cached) return cached;
148
+
149
+ NSAttributedString *text = nil;
150
+ if ([paragraph respondsToSelector:@selector(attributedText)]) {
151
+ text = [paragraph performSelector:@selector(attributedText)];
152
+ }
153
+ if (text.length == 0) return nil;
154
+
155
+ NanoIconParagraphBaselines *baselines = NanoIconLayOutBaselines(paragraph, text);
156
+ if (!baselines) return nil;
157
+
158
+ objc_setAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey, baselines, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
159
+ __weak UIView *weakParagraph = paragraph;
160
+ dispatch_async(dispatch_get_main_queue(), ^{
161
+ UIView *strongParagraph = weakParagraph;
162
+ if (strongParagraph) {
163
+ objc_setAssociatedObject(strongParagraph, kNanoIconParagraphBaselinesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
164
+ }
165
+ });
166
+ return baselines;
167
+ }
168
+
169
+ // Distance from the view's bottom edge down to the baseline RN meant it to
170
+ // sit on, rounded to the pixel grid. The attachment is matched by x; the
171
+ // nearest baseline resolves lines that start at the same x.
172
+ CGFloat NanoIconInlineBaselineOffset(UIView *view, UIView *paragraph) {
173
+ NanoIconParagraphBaselines *baselines = NanoIconBaselinesForParagraph(paragraph);
174
+ if (!baselines) return 0;
175
+
176
+ CGRect frame = [view.superview convertRect:view.frame toView:paragraph];
177
+ CGFloat bottom = CGRectGetMaxY(frame);
178
+ CGFloat nearest = bottom;
179
+ CGFloat nearestDistance = CGFLOAT_MAX;
180
+ for (const CGPoint &baseline : baselines.entries) {
181
+ if (fabs(baseline.x - frame.origin.x) > 1.5) continue;
182
+ CGFloat distance = fabs(baseline.y - bottom);
183
+ if (distance < nearestDistance) {
184
+ nearestDistance = distance;
185
+ nearest = baseline.y;
186
+ }
187
+ }
188
+ CGFloat scale = [UIScreen mainScreen].scale;
189
+ return round((bottom - nearest) * scale) / scale;
190
+ }
@@ -2,4 +2,5 @@
2
2
  #import <Foundation/Foundation.h>
3
3
 
4
4
  @interface NanoIconView : RCTViewComponentView
5
+ - (void)invalidateInlineBaseline;
5
6
  @end
@@ -3,8 +3,9 @@
3
3
  #import <CoreText/CoreText.h>
4
4
  #import <React/RCTConversions.h>
5
5
  #import <React/RCTFabricComponentsPlugins.h>
6
- #import <react/renderer/components/RNNanoIconsSpec/ComponentDescriptors.h>
6
+ #import <react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h>
7
7
  #import <react/renderer/components/RNNanoIconsSpec/Props.h>
8
+ #import "NanoIconInlineBaseline.h"
8
9
 
9
10
  using namespace facebook::react;
10
11
 
@@ -50,18 +51,22 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
50
51
  NSString *_fontFamily;
51
52
  CGFloat _fontSize;
52
53
  std::vector<CGGlyph> _glyphs;
53
- std::vector<uint32_t> _colors;
54
+ // Unresolved layer colors — may be trait-dependent (DynamicColorIOS, PlatformColor).
55
+ NSArray<UIColor *> *_layerColors;
56
+ // _layerColors resolved against the current trait collection.
54
57
  std::vector<CGColorRef> _cachedCGColors;
58
+ UIColor *_tintColor;
59
+ CGColorRef _cachedTintCGColor;
60
+ std::vector<bool> _tintable;
55
61
  CGFloat _fitScale;
56
62
  CGPoint _baselinePosition;
57
63
  BOOL _metricsValid;
58
64
 
59
65
  // Inline-in-Text detection — resolved once on first layout, cached until reparenting.
60
66
  // Standalone icons (vast majority) skip the superview walk entirely after detection.
61
- BOOL _inlineDetected;
62
- BOOL _isInlineInText;
63
- UIView * __weak _paragraphView;
64
- CGFloat _cachedBaselineOffset;
67
+ BOOL _paragraphResolved;
68
+ UIView * __weak _paragraph;
69
+ CGFloat _baselineOffset;
65
70
  BOOL _baselineOffsetValid;
66
71
 
67
72
  // Drawing sublayer for inline icons — provides a shifted pixel buffer so the
@@ -112,61 +117,19 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
112
117
  _metricsValid = YES;
113
118
  }
114
119
 
115
- // Detect whether this icon is inline inside a <Text> component and, if so,
116
- // compute the baseline offset in a single pass. Deferred to first layout
117
- // (not didMoveToSuperview) because Fabric may assemble the hierarchy bottom-up.
118
- // For standalone icons this completes in 1-3 class name checks with no
119
- // ObjC runtime method resolution or attributed string reads.
120
- - (void)_detectAndCacheInlineState {
121
- _inlineDetected = YES;
122
- _isInlineInText = NO;
123
- _paragraphView = nil;
124
- _cachedBaselineOffset = 0;
125
- _baselineOffsetValid = YES;
126
-
127
- // RCTParagraphComponentView is the immediate or near-immediate parent
128
- // when the icon is inside <Text>. Three levels covers all known layouts.
129
- UIView *current = self.superview;
130
- UIView *target = nil;
131
- for (int i = 0; i < 3 && current; i++) {
132
- if ([NSStringFromClass([current class]) isEqualToString:@"RCTParagraphComponentView"]) {
133
- target = current;
134
- break;
135
- }
136
- current = current.superview;
137
- }
138
-
139
- if (!target) return;
120
+ - (void)invalidateInlineBaseline {
121
+ _baselineOffsetValid = NO;
122
+ [self setNeedsLayout];
123
+ }
140
124
 
141
- NSAttributedString *attrStr = nil;
142
- if ([target respondsToSelector:@selector(attributedText)]) {
143
- attrStr = [target performSelector:@selector(attributedText)];
125
+ // The baseline offset depends on where RN placed the view, so a new frame
126
+ // invalidates it.
127
+ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
128
+ oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics {
129
+ [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
130
+ if (layoutMetrics.frame != oldLayoutMetrics.frame) {
131
+ _baselineOffsetValid = NO;
144
132
  }
145
- if (!attrStr || attrStr.length == 0) return;
146
-
147
- UIFont *f = [attrStr attribute:NSFontAttributeName atIndex:0 effectiveRange:nil];
148
- if (!f) return;
149
-
150
- _isInlineInText = YES;
151
- _paragraphView = target;
152
-
153
- // Derive the distance from this view's bottom edge to the text baseline.
154
- // Respects custom RN lineHeight (mapped to NSParagraphStyle.maximumLineHeight)
155
- // and any baseline offset applied by Fabric's text layout.
156
- NSParagraphStyle *style = [attrStr attribute:NSParagraphStyleAttributeName
157
- atIndex:0 effectiveRange:nil];
158
- CGFloat lineHeight = (style && style.maximumLineHeight > 0)
159
- ? style.maximumLineHeight : f.lineHeight;
160
-
161
- NSNumber *bOff = [attrStr attribute:NSBaselineOffsetAttributeName
162
- atIndex:0 effectiveRange:nil];
163
- CGFloat baselineFromLineTop = f.ascender - (bOff ? bOff.doubleValue : 0);
164
-
165
- CGFloat frameBottom = self.frame.origin.y + self.frame.size.height;
166
- CGFloat posInLine = fmod(frameBottom, lineHeight);
167
- if (posInLine < 0.01) posInLine = lineHeight;
168
-
169
- _cachedBaselineOffset = MAX(0, posInLine - baselineFromLineTop);
170
133
  }
171
134
 
172
135
  // Lazily create the drawing sublayer for inline-in-Text icons.
@@ -185,17 +148,12 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
185
148
  // Reset inline state when the view moves to a new parent.
186
149
  - (void)didMoveToSuperview {
187
150
  [super didMoveToSuperview];
188
- _inlineDetected = NO;
189
- _isInlineInText = NO;
190
- _paragraphView = nil;
151
+ _paragraphResolved = NO;
152
+ _paragraph = nil;
191
153
  _baselineOffsetValid = NO;
192
- if (_drawingLayer) {
193
- [_drawingLayer removeFromSuperlayer];
194
- _drawingLayer = nil;
195
- }
196
154
  }
197
155
 
198
- // _cachedBaselineOffset and _fitScale are both derived from bounds.
156
+ // _baselineOffset and _fitScale are both derived from bounds.
199
157
  - (void)setBounds:(CGRect)bounds {
200
158
  if (!CGSizeEqualToSize(self.bounds.size, bounds.size)) {
201
159
  _baselineOffsetValid = NO;
@@ -206,43 +164,49 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
206
164
 
207
165
  #pragma mark - Layout
208
166
 
209
- // Standalone: no work beyond metrics validation (drawing via drawRect: on self).
210
- // Inline: position the drawing sublayer with the cached baseline offset,
211
- // recomputing only when bounds change or the view is reparented.
212
167
  - (void)layoutSubviews {
213
168
  [super layoutSubviews];
214
169
  if (!_metricsValid) [self _updateMetrics];
215
-
216
- if (!_inlineDetected) {
217
- [self _detectAndCacheInlineState];
170
+ if (!_paragraphResolved) {
171
+ _paragraph = NanoIconParagraphNeedingBaselineCorrection(self);
172
+ _paragraphResolved = YES;
173
+ }
174
+ if (!_baselineOffsetValid) {
175
+ _baselineOffset = _paragraph ? NanoIconInlineBaselineOffset(self, _paragraph) : 0;
176
+ _baselineOffsetValid = YES;
218
177
  }
178
+ [self _layoutDrawingLayer];
179
+ }
219
180
 
220
- if (_isInlineInText) {
221
- if (!_baselineOffsetValid) {
222
- [self _detectAndCacheInlineState];
223
- }
224
- BOOL created = !_drawingLayer;
225
- [self _ensureDrawingLayer];
226
- CGRect newFrame = CGRectMake(0, -_cachedBaselineOffset,
227
- self.bounds.size.width, self.bounds.size.height);
228
- if (!CGRectEqualToRect(_drawingLayer.frame, newFrame)) {
229
- [CATransaction begin];
230
- [CATransaction setDisableActions:YES];
231
- _drawingLayer.frame = newFrame;
232
- [CATransaction commit];
181
+ // Standalone icons draw in drawRect:. An icon that needs a baseline correction
182
+ // draws in a sublayer shifted by the offset instead, so it can overflow the
183
+ // Yoga frame without moving the view itself.
184
+ - (void)_layoutDrawingLayer {
185
+ if (_baselineOffset == 0) {
186
+ if (_drawingLayer) {
187
+ [_drawingLayer removeFromSuperlayer];
188
+ _drawingLayer = nil;
189
+ [self setNeedsDisplay];
233
190
  }
234
- // First layout after inline detection: the layer missed the initial
235
- // setNeedsDisplay from updateProps (which targeted self before detection).
236
- if (created) [_drawingLayer setNeedsDisplay];
191
+ return;
237
192
  }
238
- // standalone: draws directly via drawRect: on self
193
+ BOOL created = !_drawingLayer;
194
+ [self _ensureDrawingLayer];
195
+ CGRect frame = CGRectMake(0, -_baselineOffset, self.bounds.size.width, self.bounds.size.height);
196
+ if (!CGRectEqualToRect(_drawingLayer.frame, frame)) {
197
+ [CATransaction begin];
198
+ [CATransaction setDisableActions:YES];
199
+ _drawingLayer.frame = frame;
200
+ [CATransaction commit];
201
+ }
202
+ if (created) [_drawingLayer setNeedsDisplay];
239
203
  }
240
204
 
241
205
  #pragma mark - Drawing
242
206
 
243
207
  // Standalone icons draw directly in this view's drawRect:.
244
208
  - (void)drawRect:(CGRect)rect {
245
- if (_isInlineInText) return; // inline icons draw via _drawingLayer
209
+ if (_drawingLayer) return;
246
210
  CGContextRef ctx = UIGraphicsGetCurrentContext();
247
211
  if (ctx) [self _drawIconInContext:ctx bounds:self.bounds];
248
212
  }
@@ -263,7 +227,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
263
227
  while (i < _glyphs.size()) {
264
228
  if (_glyphs[i] == 0) { i++; continue; }
265
229
 
266
- CGColorRef color = (i < _cachedCGColors.size()) ? _cachedCGColors[i] : NULL;
230
+ CGColorRef color = [self _colorForLayer:i];
267
231
  if (!color) {
268
232
  static CGColorRef sBlack = CGColorCreateSRGB(0, 0, 0, 1);
269
233
  color = sBlack;
@@ -278,7 +242,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
278
242
 
279
243
  while (i < _glyphs.size()) {
280
244
  if (_glyphs[i] == 0) { i++; continue; }
281
- CGColorRef next = (i < _cachedCGColors.size()) ? _cachedCGColors[i] : NULL;
245
+ CGColorRef next = [self _colorForLayer:i];
282
246
  if (i > batchStart && next != color) break;
283
247
  if (batchCount < 16) {
284
248
  posBuf[batchCount] = _baselinePosition;
@@ -318,19 +282,34 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
318
282
  - (void)_releaseCachedColors {
319
283
  for (CGColorRef c : _cachedCGColors) CGColorRelease(c);
320
284
  _cachedCGColors.clear();
285
+ if (_cachedTintCGColor) {
286
+ CGColorRelease(_cachedTintCGColor);
287
+ _cachedTintCGColor = NULL;
288
+ }
289
+ }
290
+
291
+ - (CGColorRef)_colorForLayer:(size_t)index {
292
+ if (_cachedTintCGColor && index < _tintable.size() && _tintable[index]) {
293
+ return _cachedTintCGColor;
294
+ }
295
+ return index < _cachedCGColors.size() ? _cachedCGColors[index] : NULL;
321
296
  }
322
297
 
323
- // Convert ARGB uint32 color values into cached CGColorRefs.
298
+ // Resolve the layer colors against the current traits into cached CGColorRefs.
299
+ // Resolving up front (rather than relying on UIKit's current trait collection at
300
+ // draw time) keeps the CALayer inline-in-Text path correct — CoreAnimation does
301
+ // not install a trait collection around -drawInContext:.
324
302
  - (void)_rebuildCachedColors {
325
303
  [self _releaseCachedColors];
326
- _cachedCGColors.resize(_colors.size());
327
- for (size_t i = 0; i < _colors.size(); i++) {
328
- uint32_t ci = _colors[i];
329
- _cachedCGColors[i] = CGColorCreateSRGB(
330
- ((ci >> 16) & 0xFF) / 255.0,
331
- ((ci >> 8) & 0xFF) / 255.0,
332
- ( ci & 0xFF) / 255.0,
333
- ((ci >> 24) & 0xFF) / 255.0);
304
+ UITraitCollection *traits = self.traitCollection;
305
+ _cachedCGColors.resize(_layerColors.count);
306
+ for (NSUInteger i = 0; i < _layerColors.count; i++) {
307
+ UIColor *resolved = [_layerColors[i] resolvedColorWithTraitCollection:traits];
308
+ _cachedCGColors[i] = CGColorRetain(resolved.CGColor);
309
+ }
310
+ if (_tintColor) {
311
+ UIColor *resolved = [_tintColor resolvedColorWithTraitCollection:traits];
312
+ _cachedTintCGColor = CGColorRetain(resolved.CGColor);
334
313
  }
335
314
  }
336
315
 
@@ -342,9 +321,9 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
342
321
  BOOL needsRedraw = NO;
343
322
 
344
323
  if (oldViewProps.fontFamily != newViewProps.fontFamily ||
345
- oldViewProps.fontSize != newViewProps.fontSize) {
324
+ oldViewProps.size != newViewProps.size) {
346
325
  _fontFamily = [NSString stringWithUTF8String:newViewProps.fontFamily.c_str()];
347
- _fontSize = newViewProps.fontSize;
326
+ _fontSize = newViewProps.size;
348
327
  _font = NanoIconResolveFont(_fontFamily, _fontSize);
349
328
  _metricsValid = NO;
350
329
  fontChanged = YES;
@@ -359,14 +338,31 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
359
338
 
360
339
  if (oldViewProps.colors != newViewProps.colors) {
361
340
  const auto &colors = newViewProps.colors;
362
- _colors.resize(colors.size());
341
+ NSMutableArray<UIColor *> *layerColors = [NSMutableArray arrayWithCapacity:colors.size()];
363
342
  for (size_t i = 0; i < colors.size(); i++) {
364
- _colors[i] = (uint32_t)colors[i];
343
+ UIColor *color = RCTUIColorFromSharedColor(colors[i]);
344
+ [layerColors addObject:color ?: [UIColor blackColor]];
365
345
  }
346
+ _layerColors = layerColors;
366
347
  [self _rebuildCachedColors];
367
348
  needsRedraw = YES;
368
349
  }
369
350
 
351
+ if (oldViewProps.color != newViewProps.color) {
352
+ _tintColor = newViewProps.color ? RCTUIColorFromSharedColor(newViewProps.color) : nil;
353
+ [self _rebuildCachedColors];
354
+ needsRedraw = YES;
355
+ }
356
+
357
+ if (oldViewProps.tintLayers != newViewProps.tintLayers ||
358
+ oldViewProps.codepoints != newViewProps.codepoints) {
359
+ _tintable.assign(newViewProps.codepoints.size(), false);
360
+ for (int layer : newViewProps.tintLayers) {
361
+ if (layer >= 0 && (size_t)layer < _tintable.size()) _tintable[layer] = true;
362
+ }
363
+ needsRedraw = YES;
364
+ }
365
+
370
366
  [super updateProps:props oldProps:oldProps];
371
367
  if (needsRedraw) [self _setNeedsRedraw];
372
368
  }
@@ -391,6 +387,21 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
391
387
  }
392
388
  }
393
389
 
390
+ // Trait-dependent colors (DynamicColorIOS, PlatformColor) resolve to a different
391
+ // CGColor when the interface style or contrast changes. Fabric does not re-send
392
+ // props for that, so re-resolve and redraw here.
393
+ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
394
+ [super traitCollectionDidChange:previousTraitCollection];
395
+
396
+ if (_layerColors.count == 0 && !_tintColor) return;
397
+ if (![self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
398
+ return;
399
+ }
400
+
401
+ [self _rebuildCachedColors];
402
+ [self _setNeedsRedraw];
403
+ }
404
+
394
405
  - (void)_resolveFontIfMissing {
395
406
  if (_font || _fontFamily.length == 0) return;
396
407
  _font = NanoIconResolveFont(_fontFamily, _fontSize);
@@ -402,7 +413,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
402
413
  }
403
414
 
404
415
  - (void)_setNeedsRedraw {
405
- if (_isInlineInText && _drawingLayer) {
416
+ if (_drawingLayer) {
406
417
  [_drawingLayer setNeedsDisplay];
407
418
  } else {
408
419
  [self setNeedsDisplay];
@@ -1,3 +1,4 @@
1
+ import { type PreparedSvgCache, type SvgWorkerPool } from '../src/core/pipeline/index';
1
2
  import type { NanoLogger } from './logger';
2
3
  export type IconSetConfig = {
3
4
  /** Path to folder of SVG files (relative to project root). */
@@ -36,4 +37,8 @@ export declare class IconSetBuildError extends Error {
36
37
  */
37
38
  export declare function buildAllFonts(iconSets: IconSetConfig[], projectRoot: string, options?: {
38
39
  logger?: NanoLogger;
40
+ keepOutputsOnFailure?: boolean;
41
+ preparedSvgCache?: PreparedSvgCache;
42
+ svgWorkerPool?: SvgWorkerPool;
43
+ withWeb?: boolean;
39
44
  }): Promise<BuiltFont[]>;
@@ -18,17 +18,24 @@ class IconSetBuildError extends Error {
18
18
  }
19
19
  }
20
20
  exports.IconSetBuildError = IconSetBuildError;
21
- const DEFAULT_SAFE_ZONE_RATIO = 1020 / 1024;
21
+ const DEFAULT_SAFE_ZONE_RATIO = 1;
22
22
  const DEFAULT_UPM = 1024;
23
23
  const DEFAULT_START_UNICODE = 0xe900;
24
- function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, web, logger) {
24
+ function webOutputFor(configured, withWeb) {
25
+ if (!configured)
26
+ return 'forbidden';
27
+ if (withWeb)
28
+ return 'required';
29
+ return 'ignored';
30
+ }
31
+ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger) {
25
32
  const ttfPath = path_1.default.join(outputDir, `${fontFamily}.ttf`);
26
33
  const glyphmapPath = path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`);
27
34
  const woff2Path = path_1.default.join(outputDir, `${fontFamily}.woff2`);
28
35
  if (!fs_1.default.existsSync(outputDir) ||
29
36
  !fs_1.default.existsSync(ttfPath) ||
30
37
  !fs_1.default.existsSync(glyphmapPath) ||
31
- (web && !fs_1.default.existsSync(woff2Path))) {
38
+ (webOutput === 'required' && !fs_1.default.existsSync(woff2Path))) {
32
39
  return undefined;
33
40
  }
34
41
  const glyphmap = JSON.parse(fs_1.default.readFileSync(glyphmapPath, 'utf8'));
@@ -36,11 +43,12 @@ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, web, l
36
43
  const storedFamily = glyphmap?.m?.f;
37
44
  const storedLinking = glyphmap?.m?.l === 'd' ? 'dynamic' : 'static';
38
45
  const storedWeb = glyphmap?.m?.w === true;
46
+ const webCurrent = webOutput === 'ignored' || storedWeb === (webOutput === 'required');
39
47
  if (storedHash &&
40
48
  storedFamily &&
41
49
  storedHash === inputHash &&
42
50
  storedLinking === linking &&
43
- storedWeb === web) {
51
+ webCurrent) {
44
52
  const iconCount = Object.keys(glyphmap?.i ?? {}).length;
45
53
  logger?.succeed(`${fontFamily}.ttf is up to date [${iconCount} icon${iconCount === 1 ? '' : 's'}]`);
46
54
  return storedFamily;
@@ -53,6 +61,7 @@ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, web, l
53
61
  * Skips generation for a set if that output folder already contains the expected .ttf and .glyphmap.json.
54
62
  */
55
63
  async function buildAllFonts(iconSets, projectRoot, options) {
64
+ const withWeb = options?.withWeb ?? true;
56
65
  const logger = options?.logger;
57
66
  const version = (0, packageVersion_1.packageVersion)();
58
67
  const toolchain = (0, packageVersion_1.fontToolchainVersions)();
@@ -64,7 +73,8 @@ async function buildAllFonts(iconSets, projectRoot, options) {
64
73
  const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
65
74
  const fontFamily = set.fontFamily ?? path_1.default.basename(inputDir);
66
75
  const linking = set.linking ?? 'static';
67
- const web = set.web ?? false;
76
+ const web = (set.web ?? false) && withWeb;
77
+ const webOutput = webOutputFor(set.web ?? false, withWeb);
68
78
  if (!fs_1.default.existsSync(inputDir)) {
69
79
  throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
70
80
  }
@@ -91,14 +101,14 @@ async function buildAllFonts(iconSets, projectRoot, options) {
91
101
  linking,
92
102
  web,
93
103
  };
94
- const inputHash = (0, fingerPrint_1.getFingerprintSync)(inputDir, {
104
+ const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSvgDirSync)(inputDir, {
95
105
  upm: config.upm,
96
106
  safeZone: config.safeZone,
97
107
  startUnicode: config.startUnicode,
98
108
  version,
99
109
  toolchain,
100
110
  });
101
- const currentFamily = familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, web, logger);
111
+ const currentFamily = familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger);
102
112
  if (currentFamily) {
103
113
  results.push({
104
114
  fontFamily,
@@ -113,23 +123,35 @@ async function buildAllFonts(iconSets, projectRoot, options) {
113
123
  allSkipped = false;
114
124
  const tempDir = path_1.default.join(projectRoot, '.temp_layers', fontFamily);
115
125
  logger?.start(`Building ${fontFamily} (${i + 1}/${iconSets.length})…`);
116
- if (!web && fs_1.default.existsSync(woff2Path))
126
+ if (webOutput === 'forbidden' && fs_1.default.existsSync(woff2Path)) {
117
127
  fs_1.default.unlinkSync(woff2Path);
128
+ }
118
129
  let out;
119
130
  try {
120
- out = await (0, index_1.runFontPipeline)(config, { inputDir, outputDir, tempDir }, { logger, inputHash });
131
+ out = await (0, index_1.runFontPipeline)(config, { inputDir, outputDir, tempDir }, {
132
+ logger,
133
+ inputHash,
134
+ preparedSvgCache: options?.preparedSvgCache,
135
+ svgWorkerPool: options?.svgWorkerPool,
136
+ svgHashByFile,
137
+ });
121
138
  }
122
139
  catch (err) {
123
- if (fs_1.default.existsSync(ttfPath))
124
- fs_1.default.unlinkSync(ttfPath);
125
- if (fs_1.default.existsSync(glyphmapPath))
126
- fs_1.default.unlinkSync(glyphmapPath);
127
- if (fs_1.default.existsSync(woff2Path))
128
- fs_1.default.unlinkSync(woff2Path);
140
+ if (!options?.keepOutputsOnFailure) {
141
+ if (fs_1.default.existsSync(ttfPath))
142
+ fs_1.default.unlinkSync(ttfPath);
143
+ if (fs_1.default.existsSync(glyphmapPath))
144
+ fs_1.default.unlinkSync(glyphmapPath);
145
+ if (fs_1.default.existsSync(woff2Path))
146
+ fs_1.default.unlinkSync(woff2Path);
147
+ }
129
148
  logger?.fail(err instanceof Error ? err.message : String(err));
130
149
  failures.push(fontFamily);
131
150
  continue;
132
151
  }
152
+ if (webOutput === 'ignored' && fs_1.default.existsSync(woff2Path)) {
153
+ fs_1.default.unlinkSync(woff2Path);
154
+ }
133
155
  results.push({
134
156
  fontFamily,
135
157
  family: out.family,