Skip to content

Commit

Permalink
Fix exception thrown by [RCTTextView description] on macOS
Browse files Browse the repository at this point in the history
Summary:
This method assumes a semicolon existed before the closing bracket (`>`), but only does on iOS. This instead puts the content before the closing bracket, which is always there on both platforms.

Changelog:
[macOS][Fixed] - Fix exception thrown by [RCTTextView description] on macOS

Reviewed By: sammy-SC

Differential Revision: D38074642

fbshipit-source-id: f46d15c2bf2d966d1c1430568f083e4d501d4b40
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Jul 26, 2022
1 parent e7a8d21 commit 7db6c08
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ - (instancetype)initWithFrame:(CGRect)frame
- (NSString *)description
{
NSString *superDescription = super.description;
NSRange semicolonRange = [superDescription rangeOfString:@";"];
NSString *replacement = [NSString stringWithFormat:@"; reactTag: %@; text: %@", self.reactTag, _textStorage.string];
return [superDescription stringByReplacingCharactersInRange:semicolonRange withString:replacement];
NSRange replacementRange = [superDescription rangeOfString:@">"];
NSString *replacement = [NSString stringWithFormat:@"; reactTag: %@; text: %@>", self.reactTag, _textStorage.string];
return [superDescription stringByReplacingCharactersInRange:replacementRange withString:replacement];
}

- (void)setSelectable:(BOOL)selectable
Expand Down Expand Up @@ -113,7 +113,7 @@ - (void)drawRect:(CGRect)rect
// CATextLayer disables font smoothing by default now on macOS; we follow suit.
CGContextSetShouldSmoothFonts(context, NO);
#endif

NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
[layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:_contentFrame.origin];
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:_contentFrame.origin];
Expand Down Expand Up @@ -157,7 +157,7 @@ - (void)drawRect:(CGRect)rect
[_highlightLayer removeFromSuperlayer];
_highlightLayer = nil;
}

#if TARGET_OS_MACCATALYST
CGContextRestoreGState(context);
#endif
Expand Down

0 comments on commit 7db6c08

Please sign in to comment.