Skip to content

Commit

Permalink
isIncludedInPinLayoutSizeCalculation -> `pin.isIncludedInSizeCalcul…
Browse files Browse the repository at this point in the history
…ation`
  • Loading branch information
stleamist committed May 16, 2023
1 parent 38bbd92 commit 7afd896
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 44 deletions.
Binary file added .DS_Store
Binary file not shown.
13 changes: 0 additions & 13 deletions Sources/Extensions/CALayer+PinLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
import QuartzCore

extension CALayer: Layoutable {
private struct pinlayoutAssociatedKeys {
static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
}

public typealias PinView = CALayer

public var superview: CALayer? {
Expand All @@ -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 {
/*
Expand Down
13 changes: 0 additions & 13 deletions Sources/Extensions/NSView+PinLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import Foundation
import AppKit

extension NSView: Layoutable {
private struct pinlayoutAssociatedKeys {
static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
}

public typealias PinView = NSView

public var pin: PinLayout<NSView> {
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions Sources/Extensions/UIView+PinLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -104,7 +95,6 @@ extension UIView: Layoutable, SizeCalculable {

extension UIView: AutoSizeCalculable {
private struct pinlayoutAssociatedKeys {
static var pinlayoutIsIncludedInPinLayoutSizeCalculation = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
static var pinlayoutAutoSizingRect = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
static var pinlayoutAutoSizingRectWithMargins = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
}
Expand Down
23 changes: 15 additions & 8 deletions Sources/Layoutable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

private struct pinlayoutAssociatedKeys {
static var pinlayoutIsIncludedInSizeCalculation = UnsafeMutablePointer<Int8>.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)
}
}
10 changes: 10 additions & 0 deletions Sources/PinLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public class PinLayout<PinView: Layoutable> {
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 {
Expand Down

0 comments on commit 7afd896

Please sign in to comment.