Swiftpack.co -  EdgarDegas/Delayout as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A DSL library under UIKit.
.package(url: "https://github.com/EdgarDegas/Delayout.git", from: "1.0.0")


Delayout allows you to write you UI structure code together with the layout code:

let someView = SomeView()
let label = Label()

view {  // view builder provided by Delayout
        .topInset(by: 20)
        .top(to: .bottom, of: someView, by: 8)  // constraint to sibling
        .bottomInset(by: -20)

Read wiki for detail.

Without Delayout

Even though you might already had the UIKit system DSLified, you still have to write your UI structure code and layout code separately:

let someView = SomeView()
let label = UILabel()

view.subviews {

// ......

someView.Top == view.Top
label.Top == someView.Bottom

If you try adding constraints between the view and its superview inside the subviews { /* ... */ } block, which I bet you had tried, it won't work. Because inside the block, the view has not yet been added to the superview then:

view.subviews {
        .fillHorizontally(padding: 20)  // won't work

Let alone setting up constraints between siblings, which leads to a runtime crash:

view.subviews {
        .make { /* top to someView */ }

Delayout makes it work, in 2 steps:

  1. Delay
  2. Layout

I attached an example project in the repo. A glance:

final class View: UIView {
  override init(frame: CGRect) {
    super.init(frame: frame)
    let cardView = UIView()
    self {
      cardView {
        HStack {
          UIImageView(image: UIImage(named: "Avatar"))
            .cornerRadius(avatarDimension / 2)
          VStack {
              .font(.preferredFont(forTextStyle: .headline))
              .text("Also called mums or chrysanths.")
              .font(.preferredFont(forTextStyle: .callout))
        .leadingInset(by: 20)
        .trailingInset(lessThan: -20)
        .fillVertically(padding: 20)
      .topInset(from: .safeArea, by: 16)
      .fillHorizontally(padding: 20)
        .onTap(target: self, #selector(obscuringViewTapped))
        .store(as: &obscuringView)
        .topInset(from: .safeArea, greaterThan: 0)
          to: .bottom,
          of: self,
          by: 0,
          priority: .defaultHigh,
          identifiedBy: detailViewTopConstraintID
        .store(as: &detailView)
    .onTap(target: self, #selector(tapped))

And the result:


The animation is done by updating the constant of a constraint added by Delayout, explain in this page.


Stars: 2
Last commit: 1 week 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

Default Values
1 week ago

Provide default values for parameters in some extension methods.

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