From 20f504db3c59382a2b2bf8303460241130ebc266 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Sat, 24 Feb 2024 08:46:03 -0800 Subject: [PATCH] Improve square and aspect ration implementations --- Sources/Layout/LayoutItem.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/Layout/LayoutItem.swift b/Sources/Layout/LayoutItem.swift index 702b5095..f55bf44d 100644 --- a/Sources/Layout/LayoutItem.swift +++ b/Sources/Layout/LayoutItem.swift @@ -230,8 +230,7 @@ extension LayoutItem { priority: UILayoutPriority = .required ) -> LayoutItem { addingSuperviewConstraints { layoutItem in - layoutItem.layoutItemView.widthConstraint(length).withPriority(priority) - layoutItem.layoutItemView.heightConstraint(length).withPriority(priority) + layoutItem.layoutItemView.squareConstraints(length).withPriority(priority) } } @@ -239,7 +238,9 @@ extension LayoutItem { /// /// - Returns: The layout item instance with the added constraint. public func square() -> LayoutItem { - aspectRatio(1) + addingSuperviewConstraints { layoutItem in + layoutItem.layoutItemView.squareConstraint() + } } // MARK: - Aspect Ratio @@ -256,9 +257,7 @@ extension LayoutItem { priority: UILayoutPriority = .required ) -> LayoutItem { addingSuperviewConstraints { layoutItem in - layoutItem.layoutItemView - .constraint(for: .width, to: .height, of: layoutItem.layoutItemView, multiplier: ratio) - .withPriority(priority) + layoutItem.layoutItemView.aspectRatioConstraint(ratio).withPriority(priority) } }