@@ -29,13 +29,6 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible {
29
29
var superview : PinView ? { get }
30
30
var subviews : [ PinView ] { get }
31
31
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
-
39
32
func getRect( keepTransform: Bool ) -> CGRect
40
33
func setRect( _ rect: CGRect , keepTransform: Bool )
41
34
@@ -44,8 +37,22 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible {
44
37
func isLTR( ) -> Bool
45
38
}
46
39
40
+ private struct pinlayoutAssociatedKeys {
41
+ static var pinlayoutIsIncludedInSizeCalculation = UnsafeMutablePointer< Int8> . allocate( capacity: 1 )
42
+ }
43
+
47
44
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
+
48
55
var subviewsIncludedInSizeCalculation : [ PinView ] {
49
- return subviews. filter ( \. isIncludedInPinLayoutSizeCalculation )
56
+ return subviews. filter ( \. isIncludedInSizeCalculation )
50
57
}
51
58
}
0 commit comments