TextureGroup / Texture

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

TextNode height is incorrect (bigger) when using flex wrap #620

Open olcayertas opened 7 years ago

olcayertas commented 7 years ago

I have following code to display tags:

@implementation TagsCardView

- (instancetype)initWithData:(NewsDetailV2Dto *)newsData {

    self = [super init];

    if (self) {

        self.backgroundColor = [UIColor whiteColor];

        NSArray *tags = [newsData.tag componentsSeparatedByString:@","];

        UIFont *font = [UIFont fontWithName:@"AcuminPro-Medium" size:12.0];
        UIColor *color = [UIColor grayColor];

        // Etiket kutucuklarında metni dikeyde ortalamak için eksi bottom inset veriyoruz.
        UIEdgeInsets insets = UIEdgeInsetsMake(8, 16, -8, 16);

        for (NSString *tag in tags) {
            ASTextNode *tagNode = [ASTextNode new];
            tagNode.borderColor = color.CGColor;
            tagNode.borderWidth = 1;
            tagNode.cornerRadius = 8;
            tagNode.textContainerInset = insets;
            tagNode.attributedText = [BaseCardView getAttributedString:tag font:font color:color lineSpacing:0];
            [self addSubnode:tagNode];
        }
    }

    return self;
}

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
    ASStackLayoutSpec *hls = [ASStackLayoutSpec horizontalStackLayoutSpec];
    hls.spacing = 8;
    hls.flexWrap = ASStackLayoutFlexWrapWrap;
    hls.children = self.subnodes;
    return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(8, 24, 16, 24) child:hls];
}

@end

This is happening when using flex wrap and items does not fit single line.

Normal text height:

image

Incorrect text height:

image
nguyenhuy commented 7 years ago

@olcayertas It looks like your text nodes are stretched on the cross axis. What is the constrained size passed to each text node? Layout problems like this are unfortunately hard to debug without a sample project, or the ability to inspect the layout tree via Weaver.