Skip to content

Commit

Permalink
Import css-layout measure mode changes from pull request #163
Browse files Browse the repository at this point in the history
Reviewed By: astreet

Differential Revision: D3059432

fb-gh-sync-id: 56cc13ffbc4805aa0789df62a04e19f23a438bd3
fbshipit-source-id: 56cc13ffbc4805aa0789df62a04e19f23a438bd3
  • Loading branch information
Emil Sjolander authored and Facebook Github Bot 8 committed Apr 7, 2016
1 parent 5f77f15 commit 3b5a49b
Show file tree
Hide file tree
Showing 14 changed files with 1,675 additions and 1,577 deletions.
10 changes: 5 additions & 5 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ @implementation RCTShadowText
CGFloat _effectiveLetterSpacing;
}

static css_dim_t RCTMeasure(void *context, float width, float height)
static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t widthMode, float height, css_measure_mode_t heightMode)
{
RCTShadowText *shadowText = (__bridge RCTShadowText *)context;
NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width];
NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width widthMode:widthMode];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
CGSize computedSize = [layoutManager usedRectForTextContainer:textContainer].size;
Expand Down Expand Up @@ -89,7 +89,7 @@ - (void)contentSizeMultiplierDidChange:(NSNotification *)note
UIEdgeInsets padding = self.paddingAsInsets;
CGFloat width = self.frame.size.width - (padding.left + padding.right);

NSTextStorage *textStorage = [self buildTextStorageForWidth:width];
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:CSS_MEASURE_MODE_EXACTLY];
[applierBlocks addObject:^(NSDictionary<NSNumber *, RCTText *> *viewRegistry) {
RCTText *view = viewRegistry[self.reactTag];
view.textStorage = textStorage;
Expand All @@ -106,7 +106,7 @@ - (void)applyLayoutNode:(css_node_t *)node
[self dirtyPropagation];
}

- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(css_measure_mode_t)widthMode
{
if (_cachedTextStorage && width == _cachedTextStorageWidth) {
return _cachedTextStorage;
Expand All @@ -121,7 +121,7 @@ - (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
textContainer.lineFragmentPadding = 0.0;
textContainer.lineBreakMode = _numberOfLines > 0 ? NSLineBreakByTruncatingTail : NSLineBreakByClipping;
textContainer.maximumNumberOfLines = _numberOfLines;
textContainer.size = (CGSize){isnan(width) ? CGFLOAT_MAX : width, CGFLOAT_MAX};
textContainer.size = (CGSize){widthMode == CSS_MEASURE_MODE_UNDEFINED ? CGFLOAT_MAX : width, CGFLOAT_MAX};

[layoutManager addTextContainer:textContainer];
[layoutManager ensureLayoutForTextContainer:textContainer];
Expand Down
Loading

0 comments on commit 3b5a49b

Please sign in to comment.