Created
April 18, 2016 22:18
-
-
Save MattFoley/133c3e258f9ae30821d8f091e4201fe1 to your computer and use it in GitHub Desktop.
Another React Native Crash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (RCTSizeComparison)attemptScale:(CGFloat)scale | |
inStorage:(NSTextStorage *)textStorage | |
forFrame:(CGRect)frame | |
{ | |
NSLayoutManager *layoutManager = [textStorage.layoutManagers firstObject]; | |
NSTextContainer *textContainer = [layoutManager.textContainers firstObject]; | |
NSRange glyphRange = NSMakeRange(0, textStorage.length); | |
[textStorage beginEditing]; | |
[textStorage enumerateAttribute:NSFontAttributeName | |
inRange:glyphRange | |
options:0 | |
usingBlock:^(UIFont *font, NSRange range, BOOL *stop) | |
{ | |
if (font) { | |
UIFont *originalFont = [self.attributedString attribute:NSFontAttributeName | |
atIndex:range.location | |
effectiveRange:&range]; | |
UIFont *newFont = [font fontWithSize:originalFont.pointSize * scale]; | |
[textStorage removeAttribute:NSFontAttributeName range:range]; | |
[textStorage addAttribute:NSFontAttributeName value:newFont range:range]; | |
} | |
}]; | |
[textStorage endEditing]; | |
NSInteger linesRequired = [self numberOfLinesRequired:[textStorage.layoutManagers firstObject]]; | |
CGSize requiredSize = [self calculateSize:textStorage]; | |
BOOL fitSize = requiredSize.height <= CGRectGetHeight(frame) && | |
requiredSize.width <= CGRectGetWidth(frame); | |
BOOL fitLines = linesRequired <= textContainer.maximumNumberOfLines || | |
textContainer.maximumNumberOfLines == 0; | |
if (fitLines && fitSize) { | |
if ((requiredSize.width + (CGRectGetWidth(frame) * RCTTextAutoSizeWidthErrorMargin)) > CGRectGetWidth(frame)) | |
{ | |
return RCTSizeWithinRange; | |
} else { | |
return RCTSizeTooSmall; | |
} | |
} else { | |
return RCTSizeTooLarge; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ln 16 seems to be crashing. Could likely use a range check.