Skip to content

Latest commit

 

History

History
72 lines (53 loc) · 1.56 KB

README.md

File metadata and controls

72 lines (53 loc) · 1.56 KB

Mineral

A library used to separate concerns from the original UIKit framework.

http://draveness.me/mvx-view.html

Node

public class Node: Buildable {
    public internal(set) var view: UIView = UIView()
    
    @discardableResult 
    public func size(_ size: CGSize) -> Element {
        view.size = size
        return self
    }    
}

Container

An abstract protocol

public protocol Container {
    associatedtype RelationType
    func build(closure: () -> Node) -> Relation<RelationType>
}

AbsoluteContainer

let frame = Builder<AbsoluteContainer>.build.color(UIColor.lightGray).size(self.view.frame.size)
Builder<Node>.build.color(UIColor.white).size(50)
    .attachTo(frame).origin(10)
Builder<Node>.build.color(UIColor.red).size(50)
    .attachTo(frame).center(200, 300)

RelativeContainer

let constraint = Builder<RelativeContainer>.build.color(UIColor.lightGray).size(self.view.frame.size)

let node = Builder<Node>.build.color(UIColor.white).size(50)
    .attachTo(constraint)
    .left(constraint)
    .top(constraint, offset: 20).node

Builder<Node>.build.color(UIColor.red).size(50)
    .attachTo(constraint)
    .left(node.rlt.right)
    .centerY(node)

FlexContainer

let flexbox = Builder<FlexContainer>.build.color(UIColor.lightGray).size(self.view.frame.size) { container in
    Builder<Node>.build
        .color(UIColor.white)
        .size(100)
        .attachTo(container)
    Builder<Node>.build.color(UIColor.red).size(100).attachTo(container)
}

view.addSubview(flexbox.view)