Commit e9006d9e by Orkhan Alikhanov

Renamed layout to anchor

parent 0c77e6eb
......@@ -56,15 +56,20 @@ public extension UIView {
return Layout(constraintable: self)
}
/// Anchor instance for the view.
var anchor: LayoutAnchor {
return LayoutAnchor(constraintable: self)
}
/**
Layout instance for safeAreaLayoutGuide.
Below iOS 11, it will be same as view.layout.
Anchor instance for safeAreaLayoutGuide.
Below iOS 11, it will be same as view.anchor.
*/
var safeLayout: Layout {
var safeAnchor: LayoutAnchor {
if #available(iOS 11.0, *) {
return Layout(constraintable: safeAreaLayoutGuide)
return LayoutAnchor(constraintable: safeAreaLayoutGuide)
} else {
return layout
return anchor
}
}
}
......@@ -535,8 +540,12 @@ private extension Layout {
*/
func constraint(_ attributes: [LayoutAttribute], to anchor: LayoutAnchorable, constants: [CGFloat]) -> Layout {
let from = LayoutAnchor(constraintable: constraintable, attributes: attributes)
let to = anchor as? LayoutAnchor ?? LayoutAnchor(constraintable: (anchor as? UIView) ?? (anchor as? Layout)?.constraintable, attributes: attributes)
let constraint = LayoutConstraint(fromAnchor: from, toAnchor: to, constants: constants)
var to = anchor as? LayoutAnchor
if to?.attributes.isEmpty ?? true {
let v = (anchor as? UIView) ?? (anchor as? LayoutAnchor)?.constraintable
to = LayoutAnchor(constraintable: v, attributes: attributes)
}
let constraint = LayoutConstraint(fromAnchor: from, toAnchor: to!, constants: constants)
var v = constraintable as? UIView
if #available(iOS 9.0, *), v == nil {
......
......@@ -49,13 +49,13 @@ public struct LayoutAnchor {
- Parameter view: A Constraintable.
- Parameter attributes: An array of LayoutAtrribute.
*/
init(constraintable: Constraintable?, attributes: [LayoutAttribute]) {
init(constraintable: Constraintable?, attributes: [LayoutAttribute] = []) {
self.constraintable = constraintable
self.attributes = attributes
}
}
public extension Layout {
public extension LayoutAnchor {
/// A layout anchor representing top of the view.
var top: LayoutAnchor {
return anchor(.top)
......@@ -136,7 +136,7 @@ public extension Layout {
}
}
private extension Layout {
private extension LayoutAnchor {
/**
Creates LayoutAnchor with the given attribute.
- Parameter attribute: A LayoutAttribute.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment