Permalink
Browse files

Using modern API to get available size in RCTShadowText

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 eeda4f3ceaa7733a8568c4ffb5a3d11a26f996c1
Showing with 7 additions and 11 deletions.
  1. +7 −11 Libraries/Text/RCTShadowText.m
@@ -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) {
@@ -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];
@@ -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];
@@ -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];
@@ -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;
}

0 comments on commit eeda4f3

Please sign in to comment.