Skip to content

Commit

Permalink
Using modern API to get available size in RCTShadowText
Browse files Browse the repository at this point in the history
Summary: This is just more correct.

Reviewed By: javache

Differential Revision: D5860755

fbshipit-source-id: 8ae0e92b2faedfb6dfa02f59f2a63a044bb6912d
  • Loading branch information
shergin authored and facebook-github-bot committed Sep 26, 2017
1 parent 73b596c commit eeda4f3
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,9 @@ - (void)contentSizeMultiplierDidChange:(NSNotification *)note
parentProperties = [super processUpdatedProperties:applierBlocks
parentProperties:parentProperties];

UIEdgeInsets padding = self.paddingAsInsets;
CGFloat width = self.frame.size.width - (padding.left + padding.right);


CGFloat availableWidth = self.availableSize.width;
NSNumber *parentTag = [[self reactSuperview] reactTag];
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:YGMeasureModeExactly];
NSTextStorage *textStorage = [self buildTextStorageForWidth:availableWidth widthMode:YGMeasureModeExactly];
CGRect textFrame = [self calculateTextFrame:textStorage];
BOOL selectable = _selectable;
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
Expand Down Expand Up @@ -160,7 +157,8 @@ - (void)applyLayoutToChildren:(YGNodeRef)node
absolutePosition:(CGPoint)absolutePosition
{
// Run layout on subviews.
NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:YGMeasureModeExactly];
CGFloat availableWidth = self.availableSize.width;
NSTextStorage *textStorage = [self buildTextStorageForWidth:availableWidth widthMode:YGMeasureModeExactly];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
Expand Down Expand Up @@ -480,8 +478,7 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
- (CGRect)calculateTextFrame:(NSTextStorage *)textStorage
{
CGRect textFrame = UIEdgeInsetsInsetRect((CGRect){CGPointZero, self.frame.size},
self.paddingAsInsets);

self.compoundInsets);

if (_adjustsFontSizeToFit) {
textFrame = [self updateStorage:textStorage toFitFrame:textFrame];
Expand All @@ -492,7 +489,6 @@ - (CGRect)calculateTextFrame:(NSTextStorage *)textStorage

- (CGRect)updateStorage:(NSTextStorage *)textStorage toFitFrame:(CGRect)frame
{

BOOL fits = [self attemptScale:1.0f
inStorage:textStorage
forFrame:frame];
Expand All @@ -507,8 +503,8 @@ - (CGRect)updateStorage:(NSTextStorage *)textStorage toFitFrame:(CGRect)frame
requiredSize = [self calculateSize:textStorage];
}

//Vertically center draw position for new text sizing.
frame.origin.y = self.paddingAsInsets.top + RCTRoundPixelValue((CGRectGetHeight(frame) - requiredSize.height) / 2.0f);
// Vertically center draw position for new text sizing.
frame.origin.y = self.compoundInsets.top + RCTRoundPixelValue((CGRectGetHeight(frame) - requiredSize.height) / 2.0f);
return frame;
}

Expand Down

0 comments on commit eeda4f3

Please sign in to comment.