Giter Site home page Giter Site logo

Comments (6)

srv7 avatar srv7 commented on May 27, 2024
import FlexLayout
import UIKit

class ViewController: UIViewController {
    
    let container = UIView()
    
    lazy var kindView: AKindView = {
        let view = AKindView()
        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "set", style: .plain, target: self, action: #selector(changeAction))
        view.addSubview(container)
        container.frame = view.bounds
        container.flex.paddingTop(100).direction(.column).justifyContent(.center).alignItems(.stretch).define { flex in
            flex.addItem(kindView)
        }
        kindView.setup("A")
        container.flex.layout(mode: .adjustHeight)
    }
    @objc func changeAction() {
        kindView.setup("B")
        container.flex.layout(mode: .adjustHeight)
    }
}
import FlexLayout
import UIKit

class AKindView: UIView {
    lazy var btnA: UIButton = {
        let btn = UIButton()
        btn.setTitle("ABC", for: .normal)
        btn.backgroundColor = .orange
        return btn
    }()

    lazy var btnB: UIButton = {
        let btn = UIButton()
        btn.setTitle("DEF", for: .normal)
        btn.backgroundColor = .orange
        return btn
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setup(_ x: String) {
        subviews.forEach { $0.removeFromSuperview() }
        flex.padding(15).define { flex in
            flex.addItem().width(100%).direction(.row).justifyContent(.spaceAround)
                .define { flex in
                    for i in 1 ... 4 {
                        let label = UILabel()
                        label.text = "\(x)--\(i)"
                        flex.addItem(label).height(44).width(20%)
                    }
                }

            flex.addItem().height(60).marginTop(15).direction(.row).alignItems(.stretch).define { flex in
                flex.addItem(btnA).grow(1).shrink(1)
                flex.addItem().width(11)
                flex.addItem(btnB).grow(1).shrink(1)
            }
        }
    }
}

from flexlayout.

MQLiu avatar MQLiu commented on May 27, 2024

Same issue, has anyone fixed it yet?

from flexlayout.

kennethpu avatar kennethpu commented on May 27, 2024

The issue here is that when setup() is called multiple times btnA and btnB wind up moving between different superviews. This means their corresponding node still has an associated parent when YGNodeInsertChild() is called, triggering the assert.

It looks like we previously had modified YGLayout to clean up these parent references (c303faa) but this was overwritten when we updated to Yoga 2.0. I have a PR (#242) to restore these lines and keep us from hitting the assert.

from flexlayout.

MQLiu avatar MQLiu commented on May 27, 2024

from flexlayout.

lucdion avatar lucdion commented on May 27, 2024

The fix will be merged today.

from flexlayout.

lucdion avatar lucdion commented on May 27, 2024

The fix has been released.

from flexlayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.