facebook / yoga

Yoga is an embeddable layout engine targeting web standards.
https://yogalayout.dev/
MIT License
17.31k stars 1.43k forks source link

Swift5.1 Error -- Crash #1018

Closed Aynnor closed 1 year ago

Aynnor commented 4 years ago

I want to bring yogakit to my project

But it will lead to crash, I don't know why

Tool Version
Xcode 11.5
CocoaPods 1.9.2
Podfile platform: ios 9.0
YogaKit 13.0.1
//Xcode Swift5.1 Project ViewController add this code, but Layout cannot be displayed, Even crash 

func createUI() {

        let fontNames = UIFont.fontNames(forFamilyName: "PingFang HK")
        print(fontNames)

        for i in 0..<fontNames.count {
            let label = UILabel()
            label.text = "the \(i) label.."
            label.font = UIFont.init(name: fontNames[i], size: 20)
            view.addSubview(label)

            label.configureLayout { (layout) in
                layout.isEnabled = true
            }
        }

        view.configureLayout { (layout) in
            layout.isEnabled = true
            layout.flexDirection = .column
            layout.justifyContent = .flexStart
            layout.alignItems = .flexStart
            layout.paddingLeft = 15
        }

        view.yoga.applyLayout(preservingOrigin: false)
}

Message

Xcode Crash Image

Aynnor commented 4 years ago

feeling problem is on the SceneDelegate

cntrump commented 4 years ago

Because width or height is nagative, fixed in my PR: https://github.com/facebook/yoga/pull/1026

YGLayout.m

.size =
           {
               .width = MAX(YGRoundPixelValue(bottomRight.x) -
                   YGRoundPixelValue(topLeft.x), 0),
               .height = MAX(YGRoundPixelValue(bottomRight.y) -
                   YGRoundPixelValue(topLeft.y), 0),
           },
NickGerleman commented 1 year ago

We are deprecating YogaKit as part of the Yoga 2.0 release. We are still going to release a new revision based on the current state of the repo, but won't be accepting new contributions, since we are going to be removing it from the repo after.