robb / Cartography

A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Other
7.35k stars 525 forks source link

UILayoutGuide support #268

Closed inamiy closed 6 years ago

inamiy commented 6 years ago

Hi 👋

Related to #267 where protocol LayoutItem is introduced (but not fully used yet), I think it is a good idea to further support arbitrary UILayoutGuide, i.e.

let space = UILayoutGuide()
view.addLayoutGuide(space)

constrain(view, space) { view, space in
    view.right == space.left
    ...
}

This will require other changes, e.g.:

public func constrain(_ view1: LayoutItem, _ view2: LayoutItem, replace group: ConstraintGroup? = nil, block: (LayoutProxy, LayoutProxy) -> ()) -> ConstraintGroup {
    ...
}

public struct LayoutProxy {
    ...
    internal let context: Context
    internal let layoutItem: LayoutItem

    init(_ context: Context, _ layoutItem: LayoutItem) {
        self.context = context
        self.layoutItem = layoutItem // `View` or `UILayoutGuide`
    }
}

What do you think?

inamiy commented 6 years ago

Done in #269.