TextureGroup / Texture

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

ASTextNode maximumNumberOfLines error??? #2007

Closed CainLuo closed 3 years ago

CainLuo commented 3 years ago

Hello everyone, have you ever encountered that the width becomes 0 after setting maximumNumberOfLines = 1 when using ASTextNode? If you don't set maximumNumberOfLines or maximumNumberOfLines > 1, there is no problem, here is my code.

    override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
        LayoutSpec {
            HStackLayout(spacing: 10, alignItems: .center) {
                AspectRatioLayout(ratio: CGSize(width: 70, height: 70)) {
                    avatarNode
                }
                VStackLayout(spacing: 5) {
                    HStackLayout(spacing: 10) {
                        nameNode
                        InsetLayout(insets: .zero) {
                            genderNode
                        }
                        .preferredSize(CGSize(width: 15, height: 15))
                    }
                    userIDNode
                    regionNode
                }
                .width(frame.width - 130)
                AspectRatioLayout(ratio: CGSize(width: 40, height: 40)) {
                    codeNode
                }
            }
        }
    }

    private func setUpUI() {
        automaticallyManagesSubnodes = true
        avatarNode.cornerRadius = 4
        avatarNode.borderWidth = 2
        avatarNode.style.flexGrow = 1
        avatarNode.borderColor = UIColor.white.cgColor
        avatarNode.image = UIImage.image("profile_header")
        avatarNode.style.preferredSize = CGSize(width: 70, height: 70)
        avatarNode.backgroundColor = UIColor(0x999999)
        genderNode.style.flexGrow = 1.0
        genderNode.image = UIImage.image("genderMan")
        codeNode.style.flexGrow = 1.0
        codeNode.style.preferredSize = CGSize(width: 40, height: 40)
        codeNode.setImage(UIImage.image("contactPageQRCode"), for: .normal)
        regionNode.maximumNumberOfLines = 1
    }

maximumNumberOfLines = 1 image

Don't set maximumNumberOfLines or maximumNumberOfLines > 1

image