Giter VIP home page Giter VIP logo

Comments (6)

jamztang avatar jamztang commented on August 16, 2024

Yay I got it working!

let imageText = Node(
    direction: .Column,
    padding: Edges(top: 20, bottom: 20),
    size: CGSizeMake(375, CGFloat.NaN),     // I just have to make sure I defined the size here, height is important to be Nan
    children: strings.map { (text : String) -> Node in
        let image = Node(
            size: CGSizeMake(100, 100)
        )
        let text = Node(
            flex: 1,                        // And make sure flex are set
            measure: { w in
                label.text = text
                label.preferredMaxLayoutWidth = w
                return label.sizeThatFits(CGSizeMake(w, CGFloat.max))
        })
        let row = Node(
            direction: Direction.Row,
            children:[image, text]
        )
        return row
    }
)

println(imageText.layout().frame) // (0.0, 0.0, 375.0, 912.5)

from swiftbox.

joshaber avatar joshaber commented on August 16, 2024

Glad you figured it out!

I'm going to re-open this because that does look like something's funny with maxWidth.

from swiftbox.

jamztang avatar jamztang commented on August 16, 2024

Is maxWidth something inside original Flexbox implementation or no?

from swiftbox.

joshaber avatar joshaber commented on August 16, 2024

Yeah it's in FB's flexbox implementation.

from swiftbox.

jamztang avatar jamztang commented on August 16, 2024

Then we have to either help to fix facebook's impl or patch it in SwiftBox manually

from swiftbox.

steadicat avatar steadicat commented on August 16, 2024

I just ran into a bug with maxWidth myself (it was setting the width of some flex: 1 children to zero).

To work around it, I just wrapped the root node inside an extra node with its width set to maxWidth, and then just grabbed the first child after calling layout():

  if let maxWidth = maxWidth {
    let wrapper = Node(size: CGSize(width: maxWidth, height: .nan), children: [node])
    let layout = wrapper.layout()
    return layout.children.first!
  } else {
    return node.layout()
  }

from swiftbox.

Related Issues (12)

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.