ASTextnode lineCount seems broken during layout
Hi! I have an issue while migrating from 1.9 to 2.3 : In my custom layoutThatFits method I make an ASStackLayoutSpec containing a few TextNode children. Then, I need to know the number of lines each TextNode has at this point to calculate its height. Previously it was working well with node.lineCount, but now this method returns 1 every time.
I investigated and it appears that the problem come from ASTextKitRenderer :
- (NSUInteger)lineCount
{
__block NSUInteger lineCount = 0;
[[self context] performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
for (NSRange lineRange = { 0, 0 }; NSMaxRange(lineRange) < [layoutManager numberOfGlyphs]; lineCount++) {
[layoutManager lineFragmentRectForGlyphAtIndex:NSMaxRange(lineRange) effectiveRange:&lineRange];
}
}];
return lineCount;
}
I noticed that the NSTextContainer has always a 0 frame so maybe it's why it can't calculate the right count... but can't figure out why
please update to 2.4. by using terminal go to project director and type pod update
check if this issue is happens again.
@macistador Hey can you please check the lineCount in layoutDidFinish.
/**
@abstract The number of lines in the text. Text must have been sized first.
*/
@property (nonatomic, readonly, assign) NSUInteger lineCount;
@hashemp206 thanks for the suggestion but I already tried and didn't changed anything
@EviluS I'm not sure what you mean, lineCount seems to be the problem because it's always returning 1...
@macistador My point was that in -layoutSpecThatFits: the actual lineCount is not "calculated" yet since the layout is not calculated yet.
it's what I was afraid of... I need it to calculate the layout Strange thing is it was working in previous versions Do you know some workaround ?
@macistador I was dealing with something similar few moths ago. My workaround was to implement 1 additional re-layout (setNeedsLayout) inside layoutDidFinish when a condition is met, in my case lineCount higher than some number.
I would like to avoid to do the work twice, specially as it's for a collectionView cell...