Skip to content

Commit

Permalink
Cleanup: enumerate all text attributes at once instead of doing multi…
Browse files Browse the repository at this point in the history
…ple passes
  • Loading branch information
Adam Gleitman committed Jun 25, 2024
1 parent bcbf64c commit f8f9ab0
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions packages/react-native/Libraries/Text/Text/RCTTextShadowView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ - (void)uiManagerWillPerformMounting

NSNumber *tag = self.reactTag;
NSMutableSet<NSNumber *> *descendantViewTags = [NSMutableSet new]; // [macOS] avoids duplicates

#if !TARGET_OS_OSX // [macOS]
[textStorage enumerateAttribute:RCTBaseTextShadowViewEmbeddedShadowViewAttributeName
inRange:NSMakeRange(0, textStorage.length)
options:0
Expand All @@ -95,17 +97,22 @@ - (void)uiManagerWillPerformMounting

[descendantViewTags addObject:shadowView.reactTag];
}];
// [macOS
[textStorage enumerateAttribute:RCTTextAttributesTagAttributeName
inRange:NSMakeRange(0, textStorage.length)
options:0
usingBlock:^(NSNumber *reactTag, NSRange range, __unused BOOL *stop) {
if (!reactTag || [reactTag isEqualToNumber:tag]) {
return;
}
[descendantViewTags addObject:reactTag];
}];
// macOS]
#else // [macOS
[textStorage enumerateAttributesInRange:NSMakeRange(0, textStorage.length)
options:0
usingBlock:^(NSDictionary<NSAttributedStringKey, id> *_Nonnull attrs, NSRange range, __unused BOOL * _Nonnull stop) {
id embeddedViewAttribute = attrs[RCTBaseTextShadowViewEmbeddedShadowViewAttributeName];
if ([embeddedViewAttribute isKindOfClass:[RCTShadowView class]]) {
RCTShadowView *embeddedShadowView = (RCTShadowView *)embeddedViewAttribute;
[descendantViewTags addObject:embeddedShadowView.reactTag];
}

id tagAttribute = attrs[RCTTextAttributesTagAttributeName];
if ([tagAttribute isKindOfClass:[NSNumber class]] && ![tagAttribute isEqualToNumber:tag]) {
[descendantViewTags addObject:tagAttribute];
}
}];
#endif // macOS]

[_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry) { // [macOS]
RCTTextView *textView = (RCTTextView *)viewRegistry[tag];
Expand Down

0 comments on commit f8f9ab0

Please sign in to comment.