From b443c4a3897c0031019af5dfd5d9a76d5b2f1f0a Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 2 Dec 2019 17:33:06 -0500 Subject: [PATCH] Reducing constraints. --- .../Atoms/Views/CheckboxWithLabelView.swift | 49 +++++-------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index f148863b..55f32ae9 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -7,7 +7,7 @@ // -@objcMembers open class CheckboxWithLabelView: ViewConstrainingView { +@objcMembers open class CheckboxWithLabelView: View { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -33,12 +33,10 @@ // MARK: - Constraints //-------------------------------------------------- - var checkboxWidthConstraint: NSLayoutConstraint? var checkboxHeightConstraint: NSLayoutConstraint? var checkboxTopConstraint: NSLayoutConstraint? var checkboxBottomConstraint: NSLayoutConstraint? var checkboxCenterYConstraint: NSLayoutConstraint? - var centerLabelCheckboxConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Life Cycle @@ -56,33 +54,24 @@ label.text = "" - let dimension = sizeObject?.getValueBasedOnApplicationWidth() ?? Checkbox.defaultHeightWidth - checkboxWidthConstraint = checkbox.heightAnchor.constraint(equalToConstant: dimension) - checkboxWidthConstraint?.isActive = true - checkboxHeightConstraint = checkbox.widthAnchor.constraint(equalToConstant: dimension) - checkboxHeightConstraint?.isActive = true - checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true - checkbox.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true - layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: checkbox.bottomAnchor).isActive = true - let checboxBottom = checkbox.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor) - checboxBottom.priority = UILayoutPriority(249) - checboxBottom.isActive = true - - // Allows various positions of checkbox. checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor) + checkboxBottomConstraint?.priority = .defaultHigh + checkboxBottomConstraint?.isActive = true + checkboxTopConstraint = checkbox.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor) + checkboxTopConstraint?.priority = .defaultHigh + checkboxTopConstraint?.isActive = true + checkboxCenterYConstraint = checkbox.centerYAnchor.constraint(equalTo: centerYAnchor) - centerLabelCheckboxConstraint = label.centerYAnchor.constraint(equalTo: checkbox.centerYAnchor) label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true layoutMarginsGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true - layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: label.bottomAnchor) - bottomLabelConstraint.priority = UILayoutPriority(249) + bottomLabelConstraint.priority = UILayoutPriority(250) bottomLabelConstraint.isActive = true alignCheckbox(.center) @@ -102,7 +91,7 @@ setupView() } - public convenience init() { + public convenience override init() { self.init(frame: .zero) } @@ -125,19 +114,16 @@ checkboxBottomConstraint?.isActive = false checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = true - centerLabelCheckboxConstraint?.isActive = true case .top: checkboxBottomConstraint?.isActive = false checkboxTopConstraint?.isActive = true checkboxCenterYConstraint?.isActive = false - centerLabelCheckboxConstraint?.isActive = false case .bottom: checkboxBottomConstraint?.isActive = true checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = false - centerLabelCheckboxConstraint?.isActive = false } } } @@ -145,7 +131,7 @@ /// MARK: - Molecular extension CheckboxWithLabelView { - override open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return CGFloat(Checkbox.defaultHeightWidth) } @@ -153,29 +139,18 @@ extension CheckboxWithLabelView { super.updateView(size) label.updateView(size) - - if self.checkbox.responds(to: #selector(self.updateView(_:))) { - if let dimension = sizeObject?.getValueBased(onSize: size) { - checkboxWidthConstraint?.constant = dimension - checkboxHeightConstraint?.constant = dimension - checkbox.updateView(size) - } - } - layoutIfNeeded() } - override open func alignment() -> UIStackView.Alignment { + open func alignment() -> UIStackView.Alignment { return .leading } - open override func resetConstraints() { - super.resetConstraints() + open func resetConstraints() { checkboxCenterYConstraint?.isActive = false checkboxBottomConstraint?.isActive = false checkboxTopConstraint?.isActive = false - centerLabelCheckboxConstraint?.isActive = false } open override func reset() {