diff --git a/Sources/Extensions/CALayer+PinLayout.swift b/Sources/Extensions/CALayer+PinLayout.swift index 9c8bdc5c..7eb92bea 100644 --- a/Sources/Extensions/CALayer+PinLayout.swift +++ b/Sources/Extensions/CALayer+PinLayout.swift @@ -20,7 +20,7 @@ import QuartzCore extension CALayer: Layoutable { - public typealias View = CALayer + public typealias PinView = CALayer public var superview: CALayer? { return superlayer @@ -58,7 +58,7 @@ extension CALayer: Layoutable { } public func setRect(_ rect: CGRect, keepTransform: Bool) { - let adjustedRect = Coordinates.adjustRectToDisplayScale(rect) + let adjustedRect = Coordinates.adjustRectToDisplayScale(rect) if keepTransform { /* diff --git a/Sources/Extensions/NSView+PinLayout.swift b/Sources/Extensions/NSView+PinLayout.swift index 27473998..ee81f9a0 100644 --- a/Sources/Extensions/NSView+PinLayout.swift +++ b/Sources/Extensions/NSView+PinLayout.swift @@ -23,7 +23,7 @@ import Foundation import AppKit extension NSView: Layoutable { - public typealias View = NSView + public typealias PinView = NSView public var pin: PinLayout { return PinLayout(view: self, keepTransform: true) @@ -48,7 +48,7 @@ extension NSView: Layoutable { } public func setRect(_ rect: CGRect, keepTransform: Bool) { - let adjustedRect = Coordinates.adjustRectToDisplayScale(rect) + let adjustedRect = Coordinates.adjustRectToDisplayScale(rect) if let superview = superview, !superview.isFlipped { var flippedRect = adjustedRect diff --git a/Sources/Extensions/UIView+PinLayout.swift b/Sources/Extensions/UIView+PinLayout.swift index ad6b568e..1a9c1445 100644 --- a/Sources/Extensions/UIView+PinLayout.swift +++ b/Sources/Extensions/UIView+PinLayout.swift @@ -23,7 +23,7 @@ import Foundation import UIKit extension UIView: Layoutable, SizeCalculable { - public typealias View = UIView + public typealias PinView = UIView public var pin: PinLayout { return PinLayout(view: self, keepTransform: true) @@ -59,7 +59,7 @@ extension UIView: Layoutable, SizeCalculable { } public func setRect(_ rect: CGRect, keepTransform: Bool) { - let adjustedRect = Coordinates.adjustRectToDisplayScale(rect) + let adjustedRect = Coordinates.adjustRectToDisplayScale(rect) if keepTransform { /* @@ -118,8 +118,8 @@ extension UIView: AutoSizeCalculable { } public func setAutoSizingRect(_ rect: CGRect, margins: PEdgeInsets) { - self.autoSizingRect = Coordinates.adjustRectToDisplayScale(rect) - self.autoSizingRectWithMargins = Coordinates.adjustRectToDisplayScale(rect.inset(by: margins)) + self.autoSizingRect = Coordinates.adjustRectToDisplayScale(rect) + self.autoSizingRectWithMargins = Coordinates.adjustRectToDisplayScale(rect.inset(by: margins)) } public func autoSizeThatFits(_ size: CGSize, layoutClosure: () -> Void) -> CGSize { diff --git a/Sources/Impl/Coordinates.swift b/Sources/Impl/Coordinates.swift index a8e0a1f8..0aa7f714 100644 --- a/Sources/Impl/Coordinates.swift +++ b/Sources/Impl/Coordinates.swift @@ -34,58 +34,58 @@ public func _pinlayoutSetUnitTest(scale: CGFloat?) { } } -final class Coordinates { - static func hCenter(_ view: View, keepTransform: Bool) -> CGFloat { +final class Coordinates { + static func hCenter(_ view: PinView, keepTransform: Bool) -> CGFloat { let rect = view.getRect(keepTransform: keepTransform) return rect.minX + (rect.width / 2) } - static func vCenter(_ view: View, keepTransform: Bool) -> CGFloat { + static func vCenter(_ view: PinView, keepTransform: Bool) -> CGFloat { let rect = view.getRect(keepTransform: keepTransform) return rect.minY + (rect.height / 2) } - static func topLeft(_ view: View, keepTransform: Bool) -> CGPoint { + static func topLeft(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX, y: rect.minY) } - static func topCenter(_ view: View, keepTransform: Bool) -> CGPoint { + static func topCenter(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX + (rect.width / 2), y: rect.minY) } - static func topRight(_ view: View, keepTransform: Bool) -> CGPoint { + static func topRight(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX + rect.width, y: rect.minY) } - static func centerLeft(_ view: View, keepTransform: Bool) -> CGPoint { + static func centerLeft(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX, y: rect.minY + (rect.height / 2)) } - static func center(_ view: View, keepTransform: Bool) -> CGPoint { + static func center(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX + (rect.width / 2), y: rect.minY + (rect.height / 2)) } - static func centerRight(_ view: View, keepTransform: Bool) -> CGPoint { + static func centerRight(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX + rect.width, y: rect.minY + (rect.height / 2)) } - static func bottomLeft(_ view: View, keepTransform: Bool) -> CGPoint { + static func bottomLeft(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX, y: rect.minY + rect.height) } - static func bottomCenter(_ view: View, keepTransform: Bool) -> CGPoint { + static func bottomCenter(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX + (rect.width / 2), y: rect.minY + rect.height) } - static func bottomRight(_ view: View, keepTransform: Bool) -> CGPoint { + static func bottomRight(_ view: PinView, keepTransform: Bool) -> CGPoint { let rect = view.getRect(keepTransform: keepTransform) return CGPoint(x: rect.minX + rect.width, y: rect.minY + rect.height) } diff --git a/Sources/Impl/PinLayout+Coordinates.swift b/Sources/Impl/PinLayout+Coordinates.swift index 334eb8d2..603f27f4 100644 --- a/Sources/Impl/PinLayout+Coordinates.swift +++ b/Sources/Impl/PinLayout+Coordinates.swift @@ -361,10 +361,10 @@ extension PinLayout { } } - private func computeCoordinates(_ point: CGPoint, _ layoutSuperview: View, _ referenceSuperview: View) -> CGPoint { + private func computeCoordinates(_ point: CGPoint, _ layoutSuperview: PinView, _ referenceSuperview: PinView) -> CGPoint { if layoutSuperview == referenceSuperview { return point // same superview => no coordinates conversion required. - } else if referenceSuperview == layoutSuperview.superview as? View { + } else if referenceSuperview == layoutSuperview.superview as? PinView { let layoutSuperviewRect = layoutSuperview.getRect(keepTransform: keepTransform) return CGPoint(x: point.x - layoutSuperviewRect.origin.x, y: point.y - layoutSuperviewRect.origin.y) @@ -372,7 +372,7 @@ extension PinLayout { // coordinates, but UIView.convert(...) below use transformed coordinates! // Currently we only support 1 and 2 levels. } else { - return referenceSuperview.convert(point, to: layoutSuperview as? View.View) + return referenceSuperview.convert(point, to: layoutSuperview as? PinView.PinView) } } @@ -380,7 +380,7 @@ extension PinLayout { guard let layoutSuperview = layoutSuperview(context) else { return nil } var results: [CGPoint] = [] anchors.forEach({ (anchor) in - let anchor = anchor as! AnchorImpl + let anchor = anchor as! AnchorImpl if let referenceSuperview = referenceSuperview(anchor.view, context) { results.append(computeCoordinates(anchor.point(keepTransform: keepTransform), layoutSuperview, referenceSuperview)) @@ -392,7 +392,7 @@ extension PinLayout { } internal func computeCoordinate(forEdge edge: HorizontalEdge, _ context: Context) -> CGFloat? { - let edge = edge as! HorizontalEdgeImpl + let edge = edge as! HorizontalEdgeImpl guard let layoutSuperview = layoutSuperview(context) else { return nil } guard let referenceSuperview = referenceSuperview(edge.view, context) else { return nil } @@ -401,7 +401,7 @@ extension PinLayout { } internal func computeCoordinate(forEdge edge: VerticalEdge, _ context: Context) -> CGFloat? { - let edge = edge as! VerticalEdgeImpl + let edge = edge as! VerticalEdgeImpl guard let layoutSuperview = layoutSuperview(context) else { return nil } guard let referenceSuperview = referenceSuperview(edge.view, context) else { return nil } diff --git a/Sources/Impl/PinLayout+Layouting.swift b/Sources/Impl/PinLayout+Layouting.swift index e9aacb61..d684ce85 100644 --- a/Sources/Impl/PinLayout+Layouting.swift +++ b/Sources/Impl/PinLayout+Layouting.swift @@ -45,7 +45,7 @@ extension PinLayout { isLayouted = true } - private func apply(onView view: View) { + private func apply(onView view: PinView) { displayLayoutWarnings() var newRect = view.getRect(keepTransform: keepTransform) diff --git a/Sources/Impl/PinLayout+Warning.swift b/Sources/Impl/PinLayout+Warning.swift index 0f54b4c8..352c610f 100644 --- a/Sources/Impl/PinLayout+Warning.swift +++ b/Sources/Impl/PinLayout+Warning.swift @@ -36,17 +36,17 @@ extension PinLayout { } internal func relativeEdgeContext(method: String, edge: VerticalEdge) -> String { - let edge = edge as! VerticalEdgeImpl + let edge = edge as! VerticalEdgeImpl return "\(method)(to: .\(edge.type.rawValue), of: \(viewDescription(edge.view)))" } internal func relativeEdgeContext(method: String, edge: HorizontalEdge) -> String { - let edge = edge as! HorizontalEdgeImpl + let edge = edge as! HorizontalEdgeImpl return "\(method)(to: .\(edge.type.rawValue), of: \(viewDescription(edge.view))" } internal func relativeAnchorContext(method: String, anchor: Anchor) -> String { - let anchor = anchor as! AnchorImpl + let anchor = anchor as! AnchorImpl return "\(method)(to: .\(anchor.type.rawValue), of: \(viewDescription(anchor.view)))" } @@ -114,12 +114,12 @@ extension PinLayout { } } - internal func viewDescription(_ view: View) -> String { + internal func viewDescription(_ view: PinView) -> String { let rect = view.getRect(keepTransform: keepTransform) return "(\(viewName(view)), Frame: \(rect))" } - internal func viewName(_ view: View) -> String { + internal func viewName(_ view: PinView) -> String { return "\(type(of: view))" } @@ -127,7 +127,7 @@ extension PinLayout { return "UIEdgeInsets(top: \(insets.top), left: \(insets.left), bottom: \(insets.bottom), right: \(insets.right))" } - internal func pinLayoutDisplayConsoleWarning(_ text: String, _ view: View) { + internal func pinLayoutDisplayConsoleWarning(_ text: String, _ view: PinView) { var displayText = "\nšŸ‘‰ \(text)" let rect = view.getRect(keepTransform: keepTransform) @@ -142,7 +142,7 @@ extension PinLayout { var hierarchy: [String] = [] while let parent = currentView.superview { hierarchy.insert("\(type(of: parent))", at: 0) - currentView = parent as! View + currentView = parent as! PinView } if hierarchy.count > 0 { #if swift(>=4.1) diff --git a/Sources/Impl/TypesImpl.swift b/Sources/Impl/TypesImpl.swift index 4dbfa9cf..2c07cd91 100644 --- a/Sources/Impl/TypesImpl.swift +++ b/Sources/Impl/TypesImpl.swift @@ -32,10 +32,10 @@ struct Size { var height: CGFloat? } -class EdgeListImpl: EdgeList { - internal let view: View +class EdgeListImpl: EdgeList { + internal let view: PinView - init(view: View) { + init(view: PinView) { self.view = view } @@ -52,14 +52,14 @@ class EdgeListImpl: EdgeList { var end: HorizontalEdge { return view.isLTR() ? right : left } } -class HorizontalEdgeImpl: HorizontalEdge { +class HorizontalEdgeImpl: HorizontalEdge { enum EdgeType: String { case left case hCenter case right } - let view: View + let view: PinView let type: EdgeType func x(keepTransform: Bool) -> CGFloat { @@ -72,20 +72,20 @@ class HorizontalEdgeImpl: HorizontalEdge { } } - internal init(view: View, type: EdgeType) { + internal init(view: PinView, type: EdgeType) { self.view = view self.type = type } } -class VerticalEdgeImpl: VerticalEdge { +class VerticalEdgeImpl: VerticalEdge { enum EdgeType: String { case top case vCenter case bottom } - internal let view: View + internal let view: PinView internal let type: EdgeType func y(keepTransform: Bool) -> CGFloat { @@ -99,16 +99,16 @@ class VerticalEdgeImpl: VerticalEdge { } } - internal init(view: View, type: EdgeType) { + internal init(view: PinView, type: EdgeType) { self.view = view self.type = type } } -class AnchorListImpl: AnchorList { - internal let view: View +class AnchorListImpl: AnchorList { + internal let view: PinView - internal init(view: View) { + internal init(view: PinView) { self.view = view } @@ -143,8 +143,8 @@ enum AnchorType: String { case bottomRight } -class AnchorImpl: Anchor { - let view: View +class AnchorImpl: Anchor { + let view: PinView let type: AnchorType func point(keepTransform: Bool) -> CGPoint { @@ -161,7 +161,7 @@ class AnchorImpl: Anchor { } } - fileprivate init(view: View, type: AnchorType) { + fileprivate init(view: PinView, type: AnchorType) { self.view = view self.type = type } diff --git a/Sources/Layoutable+PinLayout.swift b/Sources/Layoutable+PinLayout.swift index 02e2791b..711e4902 100644 --- a/Sources/Layoutable+PinLayout.swift +++ b/Sources/Layoutable+PinLayout.swift @@ -21,10 +21,10 @@ import Foundation extension Layoutable { public var anchor: AnchorList { - return AnchorListImpl(view: self as! View) + return AnchorListImpl(view: self as! PinView) } public var edge: EdgeList { - return EdgeListImpl(view: self as! View) + return EdgeListImpl(view: self as! PinView) } } diff --git a/Sources/Layoutable.swift b/Sources/Layoutable.swift index 76642d8e..fa4e9963 100644 --- a/Sources/Layoutable.swift +++ b/Sources/Layoutable.swift @@ -24,15 +24,15 @@ import AppKit #endif public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { - associatedtype View: Layoutable + associatedtype PinView: Layoutable - var superview: View? { get } - var subviews: [View] { get } + var superview: PinView? { get } + var subviews: [PinView] { get } func getRect(keepTransform: Bool) -> CGRect func setRect(_ rect: CGRect, keepTransform: Bool) - func convert(_ point: CGPoint, to view: View?) -> CGPoint + func convert(_ point: CGPoint, to view: PinView?) -> CGPoint func isLTR() -> Bool } diff --git a/Sources/PinLayout+Between.swift b/Sources/PinLayout+Between.swift index 7ec496dd..c3031ed2 100644 --- a/Sources/PinLayout+Between.swift +++ b/Sources/PinLayout+Between.swift @@ -29,7 +29,7 @@ extension PinLayout { // horizontallyBetween(...) // @discardableResult - public func horizontallyBetween(_ view1: View, and view2: View, aligned: VerticalAlign = .none) -> PinLayout { + public func horizontallyBetween(_ view1: PinView, and view2: PinView, aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return betweenContext("horizontallyBetween", view1, view2, aligned) } guard self.view != view1 && self.view != view2 else { warnWontBeApplied("the view being layouted cannot be used as one of the references.", context) @@ -77,7 +77,7 @@ extension PinLayout { // verticallyBetween(...) // @discardableResult - public func verticallyBetween(_ view1: View, and view2: View, aligned: HorizontalAlign = .none) -> PinLayout { + public func verticallyBetween(_ view1: PinView, and view2: PinView, aligned: HorizontalAlign = .none) -> PinLayout { func context() -> String { return betweenContext("verticallyBetween", view1, view2, aligned) } guard self.view != view1 && self.view != view2 else { warnWontBeApplied("the view being layouted cannot be used as one of the references.", context) @@ -130,15 +130,15 @@ extension PinLayout { // MARK: private extension PinLayout { - fileprivate func betweenContext(_ type: String, _ view1: View, _ view2: View, _ aligned: HorizontalAlign) -> String { + fileprivate func betweenContext(_ type: String, _ view1: PinView, _ view2: PinView, _ aligned: HorizontalAlign) -> String { return betweenContext(type, view1, view2, aligned: aligned == HorizontalAlign.none ? nil : aligned.description) } - fileprivate func betweenContext(_ type: String, _ view1: View, _ view2: View, _ aligned: VerticalAlign) -> String { + fileprivate func betweenContext(_ type: String, _ view1: PinView, _ view2: PinView, _ aligned: VerticalAlign) -> String { return betweenContext(type, view1, view2, aligned: aligned == VerticalAlign.none ? nil : aligned.description) } - private func betweenContext(_ type: String, _ view1: View, _ view2: View, aligned: String?) -> String { + private func betweenContext(_ type: String, _ view1: PinView, _ view2: PinView, aligned: String?) -> String { if let aligned = aligned { return "\(type)(\(viewDescription(view1)), \(viewDescription(view1)), aligned: .\(aligned))" } else { diff --git a/Sources/PinLayout+Relative.swift b/Sources/PinLayout+Relative.swift index e53190fd..c18df008 100644 --- a/Sources/PinLayout+Relative.swift +++ b/Sources/PinLayout+Relative.swift @@ -29,13 +29,13 @@ extension PinLayout { // above(of ...) // @discardableResult - public func above(of relativeView: View, aligned: HorizontalAlign = .none) -> PinLayout { + public func above(of relativeView: PinView, aligned: HorizontalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("above", [relativeView], aligned) } return above(of: [relativeView], aligned: aligned, context: context) } @discardableResult - public func above(of relativeViews: [View], aligned: HorizontalAlign = .none) -> PinLayout { + public func above(of relativeViews: [PinView], aligned: HorizontalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("above", relativeViews, aligned) } return above(of: relativeViews, aligned: aligned, context: context) } @@ -44,13 +44,13 @@ extension PinLayout { // below(of ...) // @discardableResult - public func below(of relativeView: View, aligned: HorizontalAlign = .none) -> PinLayout { + public func below(of relativeView: PinView, aligned: HorizontalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("below", [relativeView], aligned) } return below(of: [relativeView], aligned: aligned, context: context) } @discardableResult - public func below(of relativeViews: [View], aligned: HorizontalAlign = .none) -> PinLayout { + public func below(of relativeViews: [PinView], aligned: HorizontalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("below", relativeViews, aligned) } return below(of: relativeViews, aligned: aligned, context: context) } @@ -59,13 +59,13 @@ extension PinLayout { // left(of ...) // @discardableResult - public func left(of relativeView: View, aligned: VerticalAlign = .none) -> PinLayout { + public func left(of relativeView: PinView, aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("left", [relativeView], aligned) } return left(of: [relativeView], aligned: aligned, context: context) } @discardableResult - public func left(of relativeViews: [View], aligned: VerticalAlign = .none) -> PinLayout { + public func left(of relativeViews: [PinView], aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("left", relativeViews, aligned) } return left(of: relativeViews, aligned: aligned, context: context) } @@ -74,13 +74,13 @@ extension PinLayout { // right(of ...) // @discardableResult - public func right(of relativeView: View, aligned: VerticalAlign = .none) -> PinLayout { + public func right(of relativeView: PinView, aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("right", [relativeView], aligned) } return right(of: [relativeView], aligned: aligned, context: context) } @discardableResult - public func right(of relativeViews: [View], aligned: VerticalAlign = .none) -> PinLayout { + public func right(of relativeViews: [PinView], aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("right", relativeViews, aligned) } return right(of: relativeViews, aligned: aligned, context: context) } @@ -89,7 +89,7 @@ extension PinLayout { // before(of ...) // @discardableResult - public func before(of relativeView: View, aligned: VerticalAlign = .none) -> PinLayout { + public func before(of relativeView: PinView, aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("before", [relativeView], aligned) } if isLTR() { return left(of: [relativeView], aligned: aligned, context: context) @@ -99,7 +99,7 @@ extension PinLayout { } @discardableResult - public func before(of relativeViews: [View], aligned: VerticalAlign = .none) -> PinLayout { + public func before(of relativeViews: [PinView], aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("before", relativeViews, aligned) } if isLTR() { return left(of: relativeViews, aligned: aligned, context: context) @@ -112,7 +112,7 @@ extension PinLayout { // after(of ...) // @discardableResult - public func after(of relativeView: View, aligned: VerticalAlign = .none) -> PinLayout { + public func after(of relativeView: PinView, aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("after", [relativeView], aligned) } if isLTR() { return right(of: [relativeView], aligned: aligned, context: context) @@ -122,7 +122,7 @@ extension PinLayout { } @discardableResult - public func after(of relativeViews: [View], aligned: VerticalAlign = .none) -> PinLayout { + public func after(of relativeViews: [PinView], aligned: VerticalAlign = .none) -> PinLayout { func context() -> String { return relativeContext("after", relativeViews, aligned) } if isLTR() { return right(of: relativeViews, aligned: aligned, context: context) @@ -134,7 +134,7 @@ extension PinLayout { // MARK: private extension PinLayout { - fileprivate func above(of relativeViews: [View], aligned: HorizontalAlign, context: Context) -> PinLayout { + fileprivate func above(of relativeViews: [PinView], aligned: HorizontalAlign, context: Context) -> PinLayout { guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self } let anchors: [Anchor] @@ -154,7 +154,7 @@ extension PinLayout { return self } - fileprivate func below(of relativeViews: [View], aligned: HorizontalAlign, context: Context) -> PinLayout { + fileprivate func below(of relativeViews: [PinView], aligned: HorizontalAlign, context: Context) -> PinLayout { guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self } let anchors: [Anchor] @@ -174,7 +174,7 @@ extension PinLayout { return self } - fileprivate func left(of relativeViews: [View], aligned: VerticalAlign, context: Context) -> PinLayout { + fileprivate func left(of relativeViews: [PinView], aligned: VerticalAlign, context: Context) -> PinLayout { guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self } let anchors: [Anchor] @@ -192,7 +192,7 @@ extension PinLayout { return self } - fileprivate func right(of relativeViews: [View], aligned: VerticalAlign, context: Context) -> PinLayout { + fileprivate func right(of relativeViews: [PinView], aligned: VerticalAlign, context: Context) -> PinLayout { guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self } let anchors: [Anchor] @@ -284,7 +284,7 @@ extension PinLayout { return sum / CGFloat(list.count) } - private func validateRelativeViews(_ relativeViews: [View], context: Context) -> [View]? { + private func validateRelativeViews(_ relativeViews: [PinView], context: Context) -> [PinView]? { guard layoutSuperview(context) != nil else { return nil } guard relativeViews.count > 0 else { warnWontBeApplied("At least one view must be visible (i.e. UIView.isHidden != true) ", context) @@ -294,15 +294,15 @@ extension PinLayout { return relativeViews } - fileprivate func relativeContext(_ type: String, _ relativeViews: [View], _ aligned: HorizontalAlign) -> String { + fileprivate func relativeContext(_ type: String, _ relativeViews: [PinView], _ aligned: HorizontalAlign) -> String { return relativeContext(type, relativeViews, aligned: aligned == HorizontalAlign.none ? nil : aligned.description) } - fileprivate func relativeContext(_ type: String, _ relativeViews: [View], _ aligned: VerticalAlign) -> String { + fileprivate func relativeContext(_ type: String, _ relativeViews: [PinView], _ aligned: VerticalAlign) -> String { return relativeContext(type, relativeViews, aligned: aligned == VerticalAlign.none ? nil : aligned.description) } - fileprivate func relativeContext(_ type: String, _ relativeViews: [View], aligned: String?) -> String { + fileprivate func relativeContext(_ type: String, _ relativeViews: [PinView], aligned: String?) -> String { let relativeViewsText: String if relativeViews.count == 1 { relativeViewsText = viewDescription(relativeViews[0]) diff --git a/Sources/PinLayout+Size.swift b/Sources/PinLayout+Size.swift index 13006929..b308c37b 100644 --- a/Sources/PinLayout+Size.swift +++ b/Sources/PinLayout+Size.swift @@ -96,7 +96,7 @@ extension PinLayout { } @discardableResult - public func size(of view: View) -> PinLayout { + public func size(of view: PinView) -> PinLayout { func context() -> String { return "size(of \(viewDescription(view)))" } return setSize(view.getRect(keepTransform: keepTransform).size, context) } @@ -128,7 +128,7 @@ extension PinLayout { dimensions of an item. */ @discardableResult - public func aspectRatio(of view: View) -> PinLayout { + public func aspectRatio(of view: PinView) -> PinLayout { let rect = view.getRect(keepTransform: keepTransform) return setAdjustSizeType(.aspectRatio(rect.width / rect.height), { "aspectRatio(of: \(viewDescription(view)))" }) } diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index 4a40aa45..33d79e30 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -27,8 +27,8 @@ import Foundation public typealias PEdgeInsets = NSEdgeInsets #endif -public class PinLayout { - internal let view: View +public class PinLayout { + internal let view: PinView internal let keepTransform: Bool internal var _top: CGFloat? // offset from superview's top edge @@ -68,7 +68,7 @@ public class PinLayout { internal var isLayouted = false - init(view: View, keepTransform: Bool) { + init(view: PinView, keepTransform: Bool) { self.view = view self.keepTransform = keepTransform @@ -780,7 +780,7 @@ public class PinLayout { } @discardableResult - public func width(of view: View) -> PinLayout { + public func width(of view: PinView) -> PinLayout { let rect = view.getRect(keepTransform: keepTransform) return setWidth(rect.width, { return "width(of: \(viewDescription(view)))" }) } @@ -824,7 +824,7 @@ public class PinLayout { } @discardableResult - public func height(of view: View) -> PinLayout { + public func height(of view: PinView) -> PinLayout { let rect = view.getRect(keepTransform: keepTransform) return setHeight(rect.height, { return "height(of: \(viewDescription(view)))" }) } @@ -1218,9 +1218,9 @@ extension PinLayout { } } - internal func layoutSuperview(_ context: Context) -> View? { + internal func layoutSuperview(_ context: Context) -> PinView? { if let superview = view.superview { - return superview as? View + return superview as? PinView } else { // Disable this warning: Using XIB, layoutSubview() is called even before views have been // added, and there is no way to modify that strange behaviour of UIKit. @@ -1229,9 +1229,9 @@ extension PinLayout { } } - internal func referenceSuperview(_ referenceView: View, _ context: Context) -> View? { + internal func referenceSuperview(_ referenceView: PinView, _ context: Context) -> PinView? { if let superview = referenceView.superview { - return superview as? View + return superview as? PinView } else { warnWontBeApplied("the reference view \(viewDescription(referenceView)) must be added as a sub-view before being used as a reference.", context) return nil