mirror of
https://github.com/status-im/react-native.git
synced 2025-02-10 08:26:23 +00:00
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
This commit is contained in:
parent
73b596cfdd
commit
eeda4f3cea
@ -116,12 +116,9 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
|
|||||||
parentProperties = [super processUpdatedProperties:applierBlocks
|
parentProperties = [super processUpdatedProperties:applierBlocks
|
||||||
parentProperties:parentProperties];
|
parentProperties:parentProperties];
|
||||||
|
|
||||||
UIEdgeInsets padding = self.paddingAsInsets;
|
CGFloat availableWidth = self.availableSize.width;
|
||||||
CGFloat width = self.frame.size.width - (padding.left + padding.right);
|
|
||||||
|
|
||||||
|
|
||||||
NSNumber *parentTag = [[self reactSuperview] reactTag];
|
NSNumber *parentTag = [[self reactSuperview] reactTag];
|
||||||
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:YGMeasureModeExactly];
|
NSTextStorage *textStorage = [self buildTextStorageForWidth:availableWidth widthMode:YGMeasureModeExactly];
|
||||||
CGRect textFrame = [self calculateTextFrame:textStorage];
|
CGRect textFrame = [self calculateTextFrame:textStorage];
|
||||||
BOOL selectable = _selectable;
|
BOOL selectable = _selectable;
|
||||||
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
||||||
@ -160,7 +157,8 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
|
|||||||
absolutePosition:(CGPoint)absolutePosition
|
absolutePosition:(CGPoint)absolutePosition
|
||||||
{
|
{
|
||||||
// Run layout on subviews.
|
// 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;
|
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
|
||||||
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
|
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
|
||||||
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
|
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
|
||||||
@ -480,8 +478,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
|
|||||||
- (CGRect)calculateTextFrame:(NSTextStorage *)textStorage
|
- (CGRect)calculateTextFrame:(NSTextStorage *)textStorage
|
||||||
{
|
{
|
||||||
CGRect textFrame = UIEdgeInsetsInsetRect((CGRect){CGPointZero, self.frame.size},
|
CGRect textFrame = UIEdgeInsetsInsetRect((CGRect){CGPointZero, self.frame.size},
|
||||||
self.paddingAsInsets);
|
self.compoundInsets);
|
||||||
|
|
||||||
|
|
||||||
if (_adjustsFontSizeToFit) {
|
if (_adjustsFontSizeToFit) {
|
||||||
textFrame = [self updateStorage:textStorage toFitFrame:textFrame];
|
textFrame = [self updateStorage:textStorage toFitFrame:textFrame];
|
||||||
@ -492,7 +489,6 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
|
|||||||
|
|
||||||
- (CGRect)updateStorage:(NSTextStorage *)textStorage toFitFrame:(CGRect)frame
|
- (CGRect)updateStorage:(NSTextStorage *)textStorage toFitFrame:(CGRect)frame
|
||||||
{
|
{
|
||||||
|
|
||||||
BOOL fits = [self attemptScale:1.0f
|
BOOL fits = [self attemptScale:1.0f
|
||||||
inStorage:textStorage
|
inStorage:textStorage
|
||||||
forFrame:frame];
|
forFrame:frame];
|
||||||
@ -507,8 +503,8 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
|
|||||||
requiredSize = [self calculateSize:textStorage];
|
requiredSize = [self calculateSize:textStorage];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Vertically center draw position for new text sizing.
|
// Vertically center draw position for new text sizing.
|
||||||
frame.origin.y = self.paddingAsInsets.top + RCTRoundPixelValue((CGRectGetHeight(frame) - requiredSize.height) / 2.0f);
|
frame.origin.y = self.compoundInsets.top + RCTRoundPixelValue((CGRectGetHeight(frame) - requiredSize.height) / 2.0f);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user