diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift index f9353ec1..2b71c04e 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift @@ -21,9 +21,6 @@ import Foundation // MARK: - Constraints //------------------------------------------------------ - var leftTextWidth: NSLayoutConstraint? - var rightTextWidth: NSLayoutConstraint? - var rightTextLabelLeading: NSLayoutConstraint? var leftTextLabelTrailing: NSLayoutConstraint? @@ -75,6 +72,8 @@ import Foundation // Resolves text layout issues found between both dynamically sized labels, number is not exact but performs as required. if leftTextLabel.hasText && rightTextLabel.hasText { rightTextLabel.preferredMaxLayoutWidth = floor((size - 16) * 0.4) + } else if rightTextLabel.hasText { + rightTextLabel.preferredMaxLayoutWidth = 0.0 } } @@ -107,13 +106,13 @@ import Foundation bottomAnchor.constraint(greaterThanOrEqualTo: rightTextLabel.bottomAnchor).isActive = true - leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6) - leftTextWidth?.priority = UILayoutPriority(rawValue: 995) - leftTextWidth?.isActive = true + let leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6) + leftTextWidth.priority = UILayoutPriority(rawValue: 995) + leftTextWidth.isActive = true - rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4) - rightTextWidth?.priority = UILayoutPriority(rawValue: 906) - rightTextWidth?.isActive = true + let rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4) + rightTextWidth.priority = UILayoutPriority(rawValue: 906) + rightTextWidth.isActive = true leftTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal) rightTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal) @@ -128,25 +127,29 @@ import Foundation private func constrainLeftLabel() { - rightTextLabelLeading?.isActive = false - leftTextLabelTrailing?.isActive = false + deactivateMiddleConstraint() leftTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor) leftTextLabelTrailing?.isActive = true } private func constrainRightLabel() { - rightTextLabelLeading?.isActive = false + deactivateMiddleConstraint() rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor) rightTextLabelLeading?.isActive = true } - override open func resetConstraints() { - super.resetConstraints() + override open func reset() { + super.reset() + + deactivateMiddleConstraint() + constrainBothLabels() + } + + private func deactivateMiddleConstraint() { leftTextLabelTrailing?.isActive = false rightTextLabelLeading?.isActive = false - constrainBothLabels() } //------------------------------------------------------