Commit 0c77e6eb by Orkhan Alikhanov

Renamed layoutables to constraintable

parent c0675fa4
...@@ -32,11 +32,11 @@ import UIKit ...@@ -32,11 +32,11 @@ import UIKit
import Motion import Motion
/// A protocol that's conformed by UIView and UILayoutGuide. /// A protocol that's conformed by UIView and UILayoutGuide.
public protocol Layoutable: class { } public protocol Constraintable: class { }
@available(iOS 9.0, *) @available(iOS 9.0, *)
extension UILayoutGuide: Layoutable { } extension UILayoutGuide: Constraintable { }
extension UIView: Layoutable { } extension UIView: Constraintable { }
/// Layout extension for UIView. /// Layout extension for UIView.
public extension UIView { public extension UIView {
...@@ -53,7 +53,7 @@ public extension UIView { ...@@ -53,7 +53,7 @@ public extension UIView {
/// Layout instance for the view. /// Layout instance for the view.
var layout: Layout { var layout: Layout {
return Layout(view: self) return Layout(constraintable: self)
} }
/** /**
...@@ -62,7 +62,7 @@ public extension UIView { ...@@ -62,7 +62,7 @@ public extension UIView {
*/ */
var safeLayout: Layout { var safeLayout: Layout {
if #available(iOS 11.0, *) { if #available(iOS 11.0, *) {
return Layout(view: safeAreaLayoutGuide) return Layout(constraintable: safeAreaLayoutGuide)
} else { } else {
return layout return layout
} }
...@@ -70,20 +70,20 @@ public extension UIView { ...@@ -70,20 +70,20 @@ public extension UIView {
} }
public struct Layout { public struct Layout {
/// A weak reference to the view. /// A weak reference to the constraintable.
weak var view: Layoutable? weak var constraintable: Constraintable?
/// Parent view of the view. /// Parent view of the view.
var parent: UIView? { var parent: UIView? {
return (view as? UIView)?.superview return (constraintable as? UIView)?.superview
} }
/** /**
An initializer taking UIView. An initializer taking Constraintable.
- Parameter view: A UIView. - Parameter view: A Constraintable.
*/ */
init(view: Layoutable) { init(constraintable: Constraintable) {
self.view = view self.constraintable = constraintable
} }
} }
...@@ -494,9 +494,9 @@ private extension Layout { ...@@ -494,9 +494,9 @@ private extension Layout {
if attributes == .constantHeight || attributes == .constantWidth { if attributes == .constantHeight || attributes == .constantWidth {
attributes.removeLast() attributes.removeLast()
anchor = LayoutAnchor(view: nil, attributes: [.notAnAttribute]) anchor = LayoutAnchor(constraintable: nil, attributes: [.notAnAttribute])
} else { } else {
anchor = LayoutAnchor(view: parent, attributes: attributes) anchor = LayoutAnchor(constraintable: parent, attributes: attributes)
} }
return constraint(attributes, to: anchor, constants: constants) return constraint(attributes, to: anchor, constants: constants)
} }
...@@ -534,13 +534,13 @@ private extension Layout { ...@@ -534,13 +534,13 @@ private extension Layout {
- Returns: A Layout instance to allow chaining. - Returns: A Layout instance to allow chaining.
*/ */
func constraint(_ attributes: [LayoutAttribute], to anchor: LayoutAnchorable, constants: [CGFloat]) -> Layout { func constraint(_ attributes: [LayoutAttribute], to anchor: LayoutAnchorable, constants: [CGFloat]) -> Layout {
let from = LayoutAnchor(view: view, attributes: attributes) let from = LayoutAnchor(constraintable: constraintable, attributes: attributes)
let to = anchor as? LayoutAnchor ?? LayoutAnchor(view: (anchor as? UIView) ?? (anchor as? Layout)?.view, 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) let constraint = LayoutConstraint(fromAnchor: from, toAnchor: to, constants: constants)
var v = view as? UIView var v = constraintable as? UIView
if #available(iOS 9.0, *), v == nil { if #available(iOS 9.0, *), v == nil {
v = (view as? UILayoutGuide)?.owningView v = (constraintable as? UILayoutGuide)?.owningView
} }
let constraints = (v?.constraints ?? []) + (v?.superview?.constraints ?? []) let constraints = (v?.constraints ?? []) + (v?.superview?.constraints ?? [])
......
...@@ -38,19 +38,19 @@ extension Layout: LayoutAnchorable { } ...@@ -38,19 +38,19 @@ extension Layout: LayoutAnchorable { }
extension LayoutAnchor: LayoutAnchorable { } extension LayoutAnchor: LayoutAnchorable { }
public struct LayoutAnchor { public struct LayoutAnchor {
/// A weak reference to the view. /// A weak reference to the constraintable.
weak var view: Layoutable? weak var constraintable: Constraintable?
/// An array of LayoutAttribute for the view. /// An array of LayoutAttribute for the view.
let attributes: [LayoutAttribute] let attributes: [LayoutAttribute]
/** /**
An initializer taking view and anchor attributes. An initializer taking constraintable and anchor attributes.
- Parameter view: A UIView. - Parameter view: A Constraintable.
- Parameter attributes: An array of LayoutAtrribute. - Parameter attributes: An array of LayoutAtrribute.
*/ */
init(view: Layoutable?, attributes: [LayoutAttribute]) { init(constraintable: Constraintable?, attributes: [LayoutAttribute]) {
self.view = view self.constraintable = constraintable
self.attributes = attributes self.attributes = attributes
} }
} }
...@@ -143,7 +143,7 @@ private extension Layout { ...@@ -143,7 +143,7 @@ private extension Layout {
- Returns: A LayoutAnchor. - Returns: A LayoutAnchor.
*/ */
func anchor(_ attribute: LayoutAttribute) -> LayoutAnchor { func anchor(_ attribute: LayoutAttribute) -> LayoutAnchor {
return LayoutAnchor(view: view, attributes: [attribute]) return LayoutAnchor(constraintable: constraintable, attributes: [attribute])
} }
/** /**
...@@ -152,6 +152,6 @@ private extension Layout { ...@@ -152,6 +152,6 @@ private extension Layout {
- Returns: A LayoutAnchor. - Returns: A LayoutAnchor.
*/ */
func acnhor(_ attributes: [LayoutAttribute]) -> LayoutAnchor { func acnhor(_ attributes: [LayoutAttribute]) -> LayoutAnchor {
return LayoutAnchor(view: view, attributes: attributes) return LayoutAnchor(constraintable: constraintable, attributes: attributes)
} }
} }
...@@ -67,10 +67,10 @@ internal extension LayoutConstraint { ...@@ -67,10 +67,10 @@ internal extension LayoutConstraint {
var v: [NSLayoutConstraint] = [] var v: [NSLayoutConstraint] = []
zip(zip(fromAnchor.attributes, toAnchor.attributes), constants).forEach { zip(zip(fromAnchor.attributes, toAnchor.attributes), constants).forEach {
v.append(NSLayoutConstraint(item: fromAnchor.view as Any, v.append(NSLayoutConstraint(item: fromAnchor.constraintable as Any,
attribute: $0.0, attribute: $0.0,
relatedBy: .equal, relatedBy: .equal,
toItem: toAnchor.view, toItem: toAnchor.constraintable,
attribute: $0.1, attribute: $0.1,
multiplier: 1, multiplier: 1,
constant: $1)) constant: $1))
......
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