Skip to content

Commit

Permalink
Remove assumptions on super's description (#36374)
Browse files Browse the repository at this point in the history
Summary:
This is a change upstreamed from our fork, React Native macOS: microsoft#1088

Original description:

>We hit some crashes where replacing the chars in the string in the description was happening at an invalid range. That caused investigation into what these description methods are doing. We shouldn't have code assuming super's description will return in a certain format. Instead, just append any additional info we want to add to the end of the description.

## Changelog

[IOS] [CHANGED] -Remove assumptions on super's description

Pull Request resolved: #36374

Test Plan: CI should pass

Reviewed By: cipolleschi

Differential Revision: D43906367

Pulled By: javache

fbshipit-source-id: f83a67c5890ad1f8a73bc644be1f0f8b22b1a371
  • Loading branch information
Saadnajmi authored and facebook-github-bot committed Mar 8, 2023
1 parent 06e55ec commit a5bc6f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ - (instancetype)initWithFrame:(CGRect)frame

- (NSString *)description
{
NSString *superDescription = super.description;
NSRange replacementRange = [superDescription rangeOfString:@">"];
NSString *replacement = [NSString stringWithFormat:@"; reactTag: %@; text: %@>", self.reactTag, _textStorage.string];
return [superDescription stringByReplacingCharactersInRange:replacementRange withString:replacement];
NSString *stringToAppend = [NSString stringWithFormat:@" reactTag: %@; text: %@", self.reactTag, _textStorage.string];
return [[super description] stringByAppendingString:stringToAppend];
}

- (void)setSelectable:(BOOL)selectable
Expand Down
8 changes: 4 additions & 4 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ - (void)accessibilityDecrement

- (NSString *)description
{
NSString *superDescription = super.description;
NSRange semicolonRange = [superDescription rangeOfString:@";"];
NSString *replacement = [NSString stringWithFormat:@"; reactTag: %@;", self.reactTag];
return [superDescription stringByReplacingCharactersInRange:semicolonRange withString:replacement];
return [[super description] stringByAppendingFormat:@" reactTag: %@; frame = %@; layer = %@",
self.reactTag,
NSStringFromCGRect(self.frame),
self.layer];
}

#pragma mark - Statics for dealing with layoutGuides
Expand Down

0 comments on commit a5bc6f0

Please sign in to comment.