Fixed delayed text layout bug

This commit is contained in:
Nick Lockwood
2015-05-29 10:27:14 -07:00
parent 4097459dc9
commit 36c33b4a60
4 changed files with 18 additions and 24 deletions

View File

@@ -29,5 +29,6 @@ extern NSString *const RCTReactTagAttributeName;
@property (nonatomic, assign) NSWritingDirection writingDirection;
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width;
- (void)recomputeText;
@end

View File

@@ -72,6 +72,12 @@ static css_dim_t RCTMeasure(void *context, float width)
return textStorage;
}
- (void)recomputeText
{
[self attributedString];
[self setTextComputed];
}
- (NSAttributedString *)attributedString
{
return [self _attributedStringWithFontFamily:nil

View File

@@ -56,8 +56,6 @@ RCT_EXPORT_SHADOW_PROPERTY(numberOfLines, NSUInteger)
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)shadowViewRegistry
{
NSMutableArray *uiBlocks = [NSMutableArray new];
for (RCTShadowView *rootView in shadowViewRegistry.allObjects) {
if (![rootView isReactRootView]) {
// This isn't a root view
@@ -69,16 +67,13 @@ RCT_EXPORT_SHADOW_PROPERTY(numberOfLines, NSUInteger)
continue;
}
RCTSparseArray *reactTaggedTextStorage = [[RCTSparseArray alloc] init];
NSMutableArray *queue = [NSMutableArray arrayWithObject:rootView];
for (NSInteger i = 0; i < [queue count]; i++) {
RCTShadowView *shadowView = queue[i];
RCTAssert([shadowView isTextDirty], @"Don't process any nodes that don't have dirty text");
if ([shadowView isKindOfClass:[RCTShadowText class]]) {
RCTShadowText *shadowText = (RCTShadowText *)shadowView;
NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:shadowView.frame.size.width];
reactTaggedTextStorage[shadowText.reactTag] = textStorage;
[(RCTShadowText *)shadowView recomputeText];
} else if ([shadowView isKindOfClass:[RCTShadowRawText class]]) {
RCTLogError(@"Raw text cannot be used outside of a <Text> tag. Not rendering string: '%@'",
[(RCTShadowRawText *)shadowView text]);
@@ -92,30 +87,21 @@ RCT_EXPORT_SHADOW_PROPERTY(numberOfLines, NSUInteger)
[shadowView setTextComputed];
}
[uiBlocks addObject:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
[reactTaggedTextStorage enumerateObjectsUsingBlock:^(NSTextStorage *textStorage, NSNumber *reactTag, BOOL *stop) {
RCTText *text = viewRegistry[reactTag];
text.textStorage = textStorage;
}];
}];
}
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
for (RCTViewManagerUIBlock shadowBlock in uiBlocks) {
shadowBlock(uiManager, viewRegistry);
}
};
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {};
}
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowText *)shadowView
{
NSNumber *reactTag = shadowView.reactTag;
UIEdgeInsets padding = shadowView.paddingAsInsets;
NSTextStorage *textStorage = [shadowView buildTextStorageForWidth:shadowView.frame.size.width];
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
RCTText *text = viewRegistry[reactTag];
text.contentInset = padding;
text.textStorage = textStorage;
};
}