Swiftpack.co - dankinsoid/VDLayout as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by dankinsoid.
dankinsoid/VDLayout 3.4.3
Declarative wrapper on UIKit
⭐️ 3
🕓 1 week ago
iOS
.package(url: "https://github.com/dankinsoid/VDLayout.git", from: "3.4.3")

VDLayout

CI Status Version License Platform

Description

This repository provides a declarative way to layout in SwiftUI-style. The DSL is based on KeyPath chaining so you can use any view property, don't need to create a DSL wrapper on your custom views, but you can create custom convinience modifiers.

Example

view.add {
    UIStackView.V {
        UILabel("1")
            .chain
	    .textAlignment(.center)
	    .textColor(.red)
	    .contentPriority(.required, axis: .horizontal, type: .compression)
	    
	UILabel().chain.text("2")
        UIButton().chain.title("Button")
    }
    .alignment(.center)
    .distribution(.equalSpacing)
    .spacing(3)
    .pin(.edges)
    .pin(.width, 8)
    .pin(aspectRatio: 1 / 2)
}

Usage

Base

  • SubviewProtocol - protocol describes any type that can be used as a subview
  • SubviewsBuilder - function builder to create [SubviewProtocol], it allows use SwiftUI Views as well (also you can use any SubviewProtocol in SwiftUI ViewBuilder)
  • LtView, LtViewController - helper classes with createLayout() function to override, optional for use
  • UIKiView, UIKitViewController - SwiftUI wrappers on UIView and UIViewController: useful for PreviewProvider
  • .chain - property to create KeyPath chaining for views, after .chain you can write any property of view, then subscript with value ([value]) or Publisher to subscribe ([cb: somePublisher])
  • do {...} - function to any custom actions on view
  • add {...} - analog of addSubview but with SubviewsBuilder
  • with {...} - same as add but returns the view itself, for using in layout

Constraints

For constraints this repo use pin methods, examples:

UIView()
	.pin(.edges)
	.pin(to: .bottom, of: view2, options: .offset(4))
 .pin(.bottom, 10..., to: view3)  
	.pin(.width, to: .height, of: superview, options: .multiplier(2), .offset(10))

Installation

  1. CocoaPods

Add the following line to your Podfile:

pod 'VDLayout'

and run pod update from the podfile directory first.

  1. Swift Package Manager

Create a Package.swift file.

// swift-tools-version:5.7
import PackageDescription

let package = Package(
  name: "SomeProject",
  dependencies: [
    .package(url: "https://github.com/dankinsoid/VDLayout.git", from: "3.4.2")
  ],
  targets: [
    .target(name: "SomeProject", dependencies: ["VDLayout"])
  ]
)
$ swift build

Author

dankinsoid, [email protected]

License

VDLayout is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 3
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

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