Fixed text layout on screen rotation

Summary:
@public

setFrame:forRootView: wasn't triggering a batch update, which is required to trigger text update. This meant text wasn't re-displayed after a rotate, only after a touch.

I also found a bug that meant we weren't caching textStorage as much as we could be. Fixed that too.

Test Plan:
* Test <Text> example in UIExplorer and ensure it lays out on rotate.
* Test <Timers> example and verify text is still updating
* Products shouldn't be affected as they have separate text implementation
This commit is contained in:
Nick Lockwood 2015-06-12 11:51:09 -07:00
parent 1c5053b24d
commit 5efc1b48a5
2 changed files with 5 additions and 7 deletions

View File

@ -79,6 +79,9 @@ static css_dim_t RCTMeasure(void *context, float width)
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
{
UIEdgeInsets padding = self.paddingAsInsets;
width -= (padding.left + padding.right);
if (_cachedTextStorage && width == _cachedTextStorageWidth) {
return _cachedTextStorage;
}
@ -92,16 +95,13 @@ static css_dim_t RCTMeasure(void *context, float width)
textContainer.lineFragmentPadding = 0.0;
textContainer.lineBreakMode = _numberOfLines > 0 ? NSLineBreakByTruncatingTail : NSLineBreakByClipping;
textContainer.maximumNumberOfLines = _numberOfLines;
UIEdgeInsets padding = self.paddingAsInsets;
width -= (padding.left + padding.right);
textContainer.size = (CGSize){isnan(width) ? CGFLOAT_MAX : width, CGFLOAT_MAX};
[layoutManager addTextContainer:textContainer];
[layoutManager ensureLayoutForTextContainer:textContainer];
_cachedTextStorage = textStorage;
_cachedTextStorageWidth = width;
_cachedTextStorage = textStorage;
return textStorage;
}

View File

@ -371,9 +371,7 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
rootShadowView.frame = frame;
[rootShadowView updateLayout];
RCTViewManagerUIBlock uiBlock = [self uiBlockWithLayoutUpdateForRootView:rootShadowView];
[self addUIBlock:uiBlock];
[self flushUIBlocks];
[self batchDidComplete];
});
}