TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.29k forks source link

ASTextnode lineCount seems broken during layout #530

Open macistador opened 7 years ago

macistador commented 7 years ago

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

haashem commented 7 years ago

please update to 2.4. by using terminal go to project director and type pod update check if this issue is happens again.

EviluS commented 7 years ago

@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;
macistador commented 7 years ago

@hashemp206 thanks for the suggestion but I already tried and didn't changed anything

macistador commented 7 years ago

@EviluS I'm not sure what you mean, lineCount seems to be the problem because it's always returning 1...

EviluS commented 7 years ago

@macistador My point was that in -layoutSpecThatFits: the actual lineCount is not "calculated" yet since the layout is not calculated yet.

macistador commented 7 years ago

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 ?

EviluS commented 7 years ago

@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.

macistador commented 7 years ago

I would like to avoid to do the work twice, specially as it's for a collectionView cell...