diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..16e143c Binary files /dev/null and b/.DS_Store differ diff --git a/Sources/Extensions/CALayer+PinLayout.swift b/Sources/Extensions/CALayer+PinLayout.swift index 698e610..7eb92be 100644 --- a/Sources/Extensions/CALayer+PinLayout.swift +++ b/Sources/Extensions/CALayer+PinLayout.swift @@ -20,10 +20,6 @@ import QuartzCore extension CALayer: Layoutable { - private struct pinlayoutAssociatedKeys { - static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer.allocate(capacity: 1) - } - public typealias PinView = CALayer public var superview: CALayer? { @@ -42,15 +38,6 @@ extension CALayer: Layoutable { return PinLayout(view: self, keepTransform: false) } - public var isIncludedInPinLayoutSizeCalculation: Bool { - get { - return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation) as? Bool ?? true - } - set { - objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } - } - public func getRect(keepTransform: Bool) -> CGRect { if keepTransform { /* diff --git a/Sources/Extensions/NSView+PinLayout.swift b/Sources/Extensions/NSView+PinLayout.swift index 0b55fe5..ee81f9a 100644 --- a/Sources/Extensions/NSView+PinLayout.swift +++ b/Sources/Extensions/NSView+PinLayout.swift @@ -23,10 +23,6 @@ import Foundation import AppKit extension NSView: Layoutable { - private struct pinlayoutAssociatedKeys { - static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer.allocate(capacity: 1) - } - public typealias PinView = NSView public var pin: PinLayout { @@ -41,15 +37,6 @@ extension NSView: Layoutable { return PinLayoutObjCImpl(view: self, keepTransform: true) } - public var isIncludedInPinLayoutSizeCalculation: Bool { - get { - return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation) as? Bool ?? true - } - set { - objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } - } - public func getRect(keepTransform: Bool) -> CGRect { if let superview = superview, !superview.isFlipped { var flippedRect = frame diff --git a/Sources/Extensions/UIView+PinLayout.swift b/Sources/Extensions/UIView+PinLayout.swift index 9188f83..d6a7e10 100644 --- a/Sources/Extensions/UIView+PinLayout.swift +++ b/Sources/Extensions/UIView+PinLayout.swift @@ -37,15 +37,6 @@ extension UIView: Layoutable, SizeCalculable { return PinLayoutObjCImpl(view: self, keepTransform: true) } - public var isIncludedInPinLayoutSizeCalculation: Bool { - get { - return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation) as? Bool ?? true - } - set { - objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } - } - public func getRect(keepTransform: Bool) -> CGRect { guard !Pin.autoSizingInProgress || autoSizingRect == nil else { return autoSizingRect ?? CGRect.zero } @@ -104,7 +95,6 @@ extension UIView: Layoutable, SizeCalculable { extension UIView: AutoSizeCalculable { private struct pinlayoutAssociatedKeys { - static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer.allocate(capacity: 1) static var pinlayoutAutoSizingRect = UnsafeMutablePointer.allocate(capacity: 1) static var pinlayoutAutoSizingRectWithMargins = UnsafeMutablePointer.allocate(capacity: 1) } diff --git a/Sources/Layoutable.swift b/Sources/Layoutable.swift index d1fd835..cb70407 100644 --- a/Sources/Layoutable.swift +++ b/Sources/Layoutable.swift @@ -29,13 +29,6 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { var superview: PinView? { get } var subviews: [PinView] { get } - /// A Boolean value that determines whether the view is included in the PinLayout's size calculation. - /// - /// An excluded view does not take up space in the layout - /// when using `wrapContent(_:padding:_:)` or `autoSizeThatFits(_:layoutClosure:)`. - /// The default value is `true`. - var isIncludedInPinLayoutSizeCalculation: Bool { get set } - func getRect(keepTransform: Bool) -> CGRect func setRect(_ rect: CGRect, keepTransform: Bool) @@ -44,8 +37,22 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { func isLTR() -> Bool } +private struct pinlayoutAssociatedKeys { + static var pinlayoutIsIncludedInSizeCalculation = UnsafeMutablePointer.allocate(capacity: 1) +} + extension Layoutable { + + var isIncludedInSizeCalculation: Bool { + get { + return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInSizeCalculation) as? Bool ?? true + } + set { + objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + } + var subviewsIncludedInSizeCalculation: [PinView] { - return subviews.filter(\.isIncludedInPinLayoutSizeCalculation) + return subviews.filter(\.isIncludedInSizeCalculation) } } diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index 33d79e3..41b78ef 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -84,6 +84,16 @@ public class PinLayout { apply() } + /// A Boolean value that determines whether the view is included in the PinLayout's size calculation. + /// + /// An excluded view does not take up space in the layout + /// when using `wrapContent(_:padding:_:)` or `autoSizeThatFits(_:layoutClosure:)`. + /// The default value is `true`. + public var isIncludedInSizeCalculation: Bool { + get { return view.isIncludedInSizeCalculation } + set { view.isIncludedInSizeCalculation = newValue } + } + #if os(iOS) || os(tvOS) public var safeArea: PEdgeInsets { if let view = view as? UIView {