Skip to content

Commit 7afd896

Browse files
committed
isIncludedInPinLayoutSizeCalculation -> pin.isIncludedInSizeCalculation
1 parent 38bbd92 commit 7afd896

File tree

6 files changed

+25
-44
lines changed

6 files changed

+25
-44
lines changed

.DS_Store

6 KB
Binary file not shown.

Sources/Extensions/CALayer+PinLayout.swift

-13
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
import QuartzCore
2121

2222
extension CALayer: Layoutable {
23-
private struct pinlayoutAssociatedKeys {
24-
static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
25-
}
26-
2723
public typealias PinView = CALayer
2824

2925
public var superview: CALayer? {
@@ -42,15 +38,6 @@ extension CALayer: Layoutable {
4238
return PinLayout(view: self, keepTransform: false)
4339
}
4440

45-
public var isIncludedInPinLayoutSizeCalculation: Bool {
46-
get {
47-
return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation) as? Bool ?? true
48-
}
49-
set {
50-
objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
51-
}
52-
}
53-
5441
public func getRect(keepTransform: Bool) -> CGRect {
5542
if keepTransform {
5643
/*

Sources/Extensions/NSView+PinLayout.swift

-13
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ import Foundation
2323
import AppKit
2424

2525
extension NSView: Layoutable {
26-
private struct pinlayoutAssociatedKeys {
27-
static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
28-
}
29-
3026
public typealias PinView = NSView
3127

3228
public var pin: PinLayout<NSView> {
@@ -41,15 +37,6 @@ extension NSView: Layoutable {
4137
return PinLayoutObjCImpl(view: self, keepTransform: true)
4238
}
4339

44-
public var isIncludedInPinLayoutSizeCalculation: Bool {
45-
get {
46-
return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation) as? Bool ?? true
47-
}
48-
set {
49-
objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
50-
}
51-
}
52-
5340
public func getRect(keepTransform: Bool) -> CGRect {
5441
if let superview = superview, !superview.isFlipped {
5542
var flippedRect = frame

Sources/Extensions/UIView+PinLayout.swift

-10
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ extension UIView: Layoutable, SizeCalculable {
3737
return PinLayoutObjCImpl(view: self, keepTransform: true)
3838
}
3939

40-
public var isIncludedInPinLayoutSizeCalculation: Bool {
41-
get {
42-
return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation) as? Bool ?? true
43-
}
44-
set {
45-
objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInPinLayoutSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
46-
}
47-
}
48-
4940
public func getRect(keepTransform: Bool) -> CGRect {
5041
guard !Pin.autoSizingInProgress || autoSizingRect == nil else { return autoSizingRect ?? CGRect.zero }
5142

@@ -104,7 +95,6 @@ extension UIView: Layoutable, SizeCalculable {
10495

10596
extension UIView: AutoSizeCalculable {
10697
private struct pinlayoutAssociatedKeys {
107-
static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
10898
static var pinlayoutAutoSizingRect = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
10999
static var pinlayoutAutoSizingRectWithMargins = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
110100
}

Sources/Layoutable.swift

+15-8
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible {
2929
var superview: PinView? { get }
3030
var subviews: [PinView] { get }
3131

32-
/// A Boolean value that determines whether the view is included in the PinLayout's size calculation.
33-
///
34-
/// An excluded view does not take up space in the layout
35-
/// when using `wrapContent(_:padding:_:)` or `autoSizeThatFits(_:layoutClosure:)`.
36-
/// The default value is `true`.
37-
var isIncludedInPinLayoutSizeCalculation: Bool { get set }
38-
3932
func getRect(keepTransform: Bool) -> CGRect
4033
func setRect(_ rect: CGRect, keepTransform: Bool)
4134

@@ -44,8 +37,22 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible {
4437
func isLTR() -> Bool
4538
}
4639

40+
private struct pinlayoutAssociatedKeys {
41+
static var pinlayoutIsIncludedInSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
42+
}
43+
4744
extension Layoutable {
45+
46+
var isIncludedInSizeCalculation: Bool {
47+
get {
48+
return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInSizeCalculation) as? Bool ?? true
49+
}
50+
set {
51+
objc_setAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutIsIncludedInSizeCalculation, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
52+
}
53+
}
54+
4855
var subviewsIncludedInSizeCalculation: [PinView] {
49-
return subviews.filter(\.isIncludedInPinLayoutSizeCalculation)
56+
return subviews.filter(\.isIncludedInSizeCalculation)
5057
}
5158
}

Sources/PinLayout.swift

+10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ public class PinLayout<PinView: Layoutable> {
8484
apply()
8585
}
8686

87+
/// A Boolean value that determines whether the view is included in the PinLayout's size calculation.
88+
///
89+
/// An excluded view does not take up space in the layout
90+
/// when using `wrapContent(_:padding:_:)` or `autoSizeThatFits(_:layoutClosure:)`.
91+
/// The default value is `true`.
92+
public var isIncludedInSizeCalculation: Bool {
93+
get { return view.isIncludedInSizeCalculation }
94+
set { view.isIncludedInSizeCalculation = newValue }
95+
}
96+
8797
#if os(iOS) || os(tvOS)
8898
public var safeArea: PEdgeInsets {
8999
if let view = view as? UIView {

0 commit comments

Comments
 (0)