Swift wrapper of facebook/yoga (CSS Flexbox layout engine).
Swift Objective-C
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Assets
Configurations Add Sources & Playground Jan 4, 2017
Externals Add Sources & Playground Jan 4, 2017
Flexbox.xcodeproj
Flexbox.xcworkspace Add Sources & Playground Jan 4, 2017
FlexboxPlayground.playground [Playground] Update Measure Jan 6, 2017
Sources Add Sources & Playground Jan 4, 2017
Tests
.gitignore Add Sources & Playground Jan 4, 2017
.gitmodules Add Sources & Playground Jan 4, 2017
.swiftlint.yml Add Sources & Playground Jan 4, 2017
LICENSE Initial commit Jan 4, 2017
README.md Add Sources & Playground Jan 4, 2017

README.md

Flexbox

Swift wrapper of facebook/yoga, a cross-platform CSS Flexbox layout engine that is lightweight, runs asynchronously, and is far simpler than AutoLayout.

If you are new to CSS Flexbox, visit following links and have fun :)

Example

let node = Node(
    size: CGSize(width: 300, height: 100),
    children: [
        Node(size: CGSize(width: 20, height: 20)),
        Node(size: CGSize(width: 40, height: 80)),
        Node(size: CGSize(width: 60, height: 40)),
    ],
    flexDirection: .row,
    justifyContent: ... // .flexStart, .center, .flexEnd, .spaceBetween, .spaceAround
)

let view = ... // prepare view hierarchy

DispatchQueue.global.async {
    let layout = node.layout()

    DispatchQueue.main.async {
        layout.apply(view)
    }
}

This will result:

Please see FlexboxPlayground for more examples.

Acknowledgement

The original idea is from joshaber/SwiftBox.

License

MIT