Simple utilities for getting things done.
Simple Layout Engine
A simplistic layout engine. Think what if CGRectDivide()
went all the way.
let layout = Layout(parentFrame: frame, direction: .column)
try layout.add(item: .flexible)
try layout.add(item: .height(200))
let topFrame = try layout.frame(at: 0)
let bottomFrame = try layout.frame(at: 1)
addSubview(SLECreateView(topFrame, .red))
addSubview(SLECreateView(bottomFrame, .blue))
Visual Formatting Language
Simple wrapper around Apple's ascii based constraints. But also stateful.
VFL(self)
.add(subview: MyView(), name: "view")
.appendConstraints(formats: ["H:|[view(320)]|", "V:|[view(480)]|"])
But unlike other wrappers, VFL is meant to be used as a supplement and not a replacement. So you can also add constraints created using system API. Here's an example that creates a view of size 320x480 and aligns it to the center of parent
let view = VFLColorView()
VFL(self)
.add(subview: view, name: "view")
.appendConstraints(formats: [
"H:[view(320)]", "V:[view(480)]",]
)
.appendConstraints([
NSLayoutConstraint(
item: view, attribute: .centerX,
relatedBy: .equal,
toItem: self, attribute: .centerX,
multiplier: 1, constant: 0
),
NSLayoutConstraint(
item: view, attribute: .centerY,
relatedBy: .equal,
toItem: self, attribute: .centerY,
multiplier: 1, constant: 0
)
])
Feedback Loop is Cool
Best way to build GUI apps!
enum AsyncViewModel {
case loading
case success(UIView)
case error(AppError)
}
class AsyncView: View<AsyncViewModel>, ContentViewBindable {
var contentView: UIView { self }
override func setUp() {
super.setUp()
backgroundColor = .white
}
override func viewModelDidUpdate() {
super.viewModelDidUpdate()
switch viewModel {
case .loading:
self.view = LoadingView(true)
case .success(let view):
self.view = view
case .error(let error):
self.view = ErrorView(error)
}
}
}