Swiftpack.co -  cntrump/SwiftYogaKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
cntrump/SwiftYogaKit
Cross-platform layout engine, support iOS/macOS/tvOS, ported version of YogaKit.
.package(url: "https://github.com/cntrump/SwiftYogaKit.git", from: "v1.0.0")

SwiftYogaKit

Ported version of YogaKit.

Dependency on yoga.

Install

SPM (Swift Package Manager)

package respository URL: https://github.com/cntrump/SwiftYogaKit.git

Carthage

github "cntrump/SwiftYogaKit" ~> 1.0.0

Usage

import SwiftYogaKit

Add swizzle for auto apply layout.

iOS / tvOS

func applicationDidFinishLaunching(_ application: UIApplication) {
    UIView.SwiftYogaKitSwizzle()
}

macOS

func applicationWillFinishLaunching(_ aNotification: Notification) {
    NSView.SwiftYogaKitSwizzle()
}

A simple layout

override func viewDidLoad() {

    let root = self.view!
    root.backgroundColor = .white
    root.yoga
        .alignItems(.center)
        .justifyContent(.center)

    let child1 = UIView()
    child1.backgroundColor = .blue
    child1.yoga
        .width(100)
        .height(10)
        .marginBottom(25)
    root.addSubview(child1)

    let child2 = UIView()
    child2.backgroundColor = .green
    child2.yoga
        .alignSelf(.flexEnd)
        .width(200)
        .height(200)
    root.addSubview(child2)

    let child3 = UIView()
    child3.backgroundColor = .yellow
    child3.yoga
        .alignSelf(.flexStart)
        .width(100)
        .height(100)
    root.addSubview(child3)
}

Self-sizing Table View Cells

tableView.estimatedRowHeight = UITableView.automaticDimension
tableView.rowHeight = UITableView.automaticDimension

Subclass UITableViewCell, calculate cell size in sizeThatFits(_:)

override func sizeThatFits(_ size: CGSize) -> CGSize {
    var w: CGFloat = 0
    if #available(iOS 11.0, *) {
        w = size.width - self.safeAreaInsets.left - self.safeAreaInsets.right
    }

    return contentView.yoga.calculateLayout(size: CGSize(width: w, height: .nan))
}

GitHub

link
Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

2 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API