changes to improve
This commit is contained in:
parent
9186ca0839
commit
ac8de65e24
@ -14,8 +14,8 @@ import Foundation
|
||||
// MARK: - Outlets
|
||||
//------------------------------------------------------
|
||||
|
||||
let leftTextLabel = Label.commonLabelB1(true)
|
||||
let rightTextLabel = Label.commonLabelB1(true)
|
||||
let leftTextLabel = Label.createLabelBoldBodySmall(true)
|
||||
let rightTextLabel = Label.createLabelBoldBodySmall(true)
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
@ -23,6 +23,33 @@ import Foundation
|
||||
|
||||
var rightTextLabelLeading: NSLayoutConstraint?
|
||||
var leftTextLabelTrailing: NSLayoutConstraint?
|
||||
var rightTextLabelTrailing: NSLayoutConstraint?
|
||||
|
||||
private func constrainLeftLabelOnly() {
|
||||
|
||||
deactivateMiddleConstraint()
|
||||
leftTextLabelTrailing?.isActive = false
|
||||
leftTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor)
|
||||
leftTextLabelTrailing?.isActive = true
|
||||
}
|
||||
|
||||
private func constrainRightLabelOnly() {
|
||||
|
||||
deactivateMiddleConstraint()
|
||||
rightTextLabelLeading?.isActive = false
|
||||
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||
rightTextLabelLeading?.isActive = true
|
||||
|
||||
rightTextLabelTrailing?.isActive = false
|
||||
rightTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightTextLabel.trailingAnchor)
|
||||
rightTextLabelTrailing?.isActive = true
|
||||
}
|
||||
|
||||
private func deactivateMiddleConstraint() {
|
||||
|
||||
leftTextLabelTrailing?.isActive = false
|
||||
rightTextLabelLeading?.isActive = false
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - Initialization
|
||||
@ -43,8 +70,6 @@ import Foundation
|
||||
override open func setupView() {
|
||||
super.setupView()
|
||||
|
||||
guard subviews.isEmpty else { return }
|
||||
|
||||
addSubview(leftTextLabel)
|
||||
addSubview(rightTextLabel)
|
||||
|
||||
@ -67,7 +92,7 @@ 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 {
|
||||
let padding = MFStyler.defaultHorizontalPadding(forSize: size) * 2
|
||||
let maximumTextWidth = (size - (padding + 16)) * 0.4
|
||||
let maximumTextWidth = (size - (padding + Padding.Four)) * 0.4
|
||||
// Subtracting 10 resolves issues of SE and iPad
|
||||
rightTextLabel.preferredMaxLayoutWidth = round(maximumTextWidth) - 10
|
||||
} else {
|
||||
@ -84,57 +109,39 @@ import Foundation
|
||||
leftTextLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||
leftTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
||||
|
||||
let leftTextBottom = leftTextLabel.bottomAnchor.constraint(equalTo: bottomAnchor)
|
||||
let leftTextBottom = bottomAnchor.constraint(equalTo: leftTextLabel.bottomAnchor)
|
||||
leftTextBottom.priority = UILayoutPriority(249)
|
||||
leftTextBottom.isActive = true
|
||||
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: leftTextLabel.bottomAnchor).isActive = true
|
||||
|
||||
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor, constant: 16)
|
||||
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor, constant: Padding.Four)
|
||||
rightTextLabelLeading?.isActive = true
|
||||
|
||||
rightTextLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||
let rightLayout = layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightTextLabel.trailingAnchor)
|
||||
rightLayout.priority = UILayoutPriority(rawValue: 995)
|
||||
rightLayout.isActive = true
|
||||
|
||||
let rightTextBottom = rightTextLabel.bottomAnchor.constraint(equalTo: bottomAnchor)
|
||||
rightTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightTextLabel.trailingAnchor)
|
||||
rightTextLabelTrailing?.priority = UILayoutPriority(rawValue: 999)
|
||||
rightTextLabelTrailing?.isActive = true
|
||||
|
||||
let rightTextBottom = bottomAnchor.constraint(equalTo: rightTextLabel.bottomAnchor)
|
||||
rightTextBottom.priority = UILayoutPriority(rawValue: 249)
|
||||
rightTextBottom.isActive = true
|
||||
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: rightTextLabel.bottomAnchor).isActive = true
|
||||
|
||||
let leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6)
|
||||
let leftTextWidth = leftTextLabel.widthAnchor.constraint(equalTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6)
|
||||
leftTextWidth.priority = UILayoutPriority(rawValue: 995)
|
||||
leftTextWidth.isActive = true
|
||||
|
||||
let rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4)
|
||||
rightTextWidth.priority = UILayoutPriority(rawValue: 906)
|
||||
let rightTextWidth = rightTextLabel.widthAnchor.constraint(equalTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4)
|
||||
rightTextWidth.priority = UILayoutPriority(rawValue: 995)
|
||||
rightTextWidth.isActive = true
|
||||
|
||||
leftTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
|
||||
rightTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||
|
||||
leftTextLabel.setContentHuggingPriority(.required, for: .vertical)
|
||||
rightTextLabel.setContentHuggingPriority(.required, for: .vertical)
|
||||
|
||||
rightTextLabel.setContentHuggingPriority(.required, for: .horizontal)
|
||||
leftTextLabel.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
rightTextLabel.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
rightTextLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||
}
|
||||
|
||||
private func constrainLeftLabel() {
|
||||
|
||||
deactivateMiddleConstraint()
|
||||
leftTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor)
|
||||
leftTextLabelTrailing?.isActive = true
|
||||
}
|
||||
|
||||
private func constrainRightLabel() {
|
||||
|
||||
deactivateMiddleConstraint()
|
||||
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||
rightTextLabelLeading?.isActive = true
|
||||
rightTextLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
}
|
||||
|
||||
override open func reset() {
|
||||
@ -144,31 +151,31 @@ import Foundation
|
||||
constrainBothLabels()
|
||||
leftTextLabel.text = ""
|
||||
rightTextLabel.text = ""
|
||||
leftTextLabel.textAlignment = .left
|
||||
rightTextLabel.textAlignment = .right
|
||||
backgroundColor = nil
|
||||
}
|
||||
|
||||
private func deactivateMiddleConstraint() {
|
||||
|
||||
leftTextLabelTrailing?.isActive = false
|
||||
rightTextLabelLeading?.isActive = false
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - Atomization
|
||||
//------------------------------------------------------
|
||||
|
||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let leftRightLabelModel = model as? LeftRightLabelModel else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let leftRightLabelModel = model as? LeftRightLabelModel else { return }
|
||||
|
||||
leftTextLabel.set(with: leftRightLabelModel.leftText, delegateObject, additionalData)
|
||||
rightTextLabel.setOptional(with: leftRightLabelModel.rightText, delegateObject, additionalData)
|
||||
|
||||
|
||||
// Label defaults to .left if no textAlignment value is provided in model.
|
||||
rightTextLabel.textAlignment = leftRightLabelModel.rightText?.textAlignment ?? .right
|
||||
|
||||
if !leftTextLabel.hasText {
|
||||
constrainRightLabel()
|
||||
constrainRightLabelOnly()
|
||||
|
||||
} else if !rightTextLabel.hasText {
|
||||
constrainLeftLabel()
|
||||
constrainLeftLabelOnly()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user