Merge branch 'feature/widow_label' into 'develop'

Inconsistent Intrinsic size.

See merge request BPHV_MIPS/mvm_core_ui!659
This commit is contained in:
Pfeil, Scott Robert 2021-02-01 15:09:10 -05:00
commit 0e5fe5949d
2 changed files with 31 additions and 43 deletions

View File

@ -38,7 +38,7 @@ public typealias ActionBlock = () -> ()
} }
public var getRange: NSRange { public var getRange: NSRange {
return NSRange(location: 0, length: text?.count ?? 0) NSRange(location: 0, length: text?.count ?? 0)
} }
//------------------------------------------------------ //------------------------------------------------------

View File

@ -19,19 +19,15 @@ open class HeadlineBody: View {
// MARK: - Constraints // MARK: - Constraints
//-------------------------------------------------- //--------------------------------------------------
var spaceBetweenLabelsConstant = PaddingOne var spaceBetweenLabelsConstant = Padding.One
var spaceBetweenLabels: NSLayoutConstraint? var spaceBetweenLabels: NSLayoutConstraint?
var leftConstraintTitle: NSLayoutConstraint?
var rightConstraintTitle: NSLayoutConstraint?
var leftConstraintMessage: NSLayoutConstraint?
var rightConstraintMessage: NSLayoutConstraint?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Methods // MARK: - Methods
//-------------------------------------------------- //--------------------------------------------------
func hasText() -> Bool { func hasText() -> Bool {
return headlineLabel.hasText || messageLabel.hasText headlineLabel.hasText || messageLabel.hasText
} }
// MARK: - Styling // MARK: - Styling
@ -57,13 +53,13 @@ open class HeadlineBody: View {
func styleLandingPageHeader() { func styleLandingPageHeader() {
headlineLabel.setFontStyle(.Title2XLarge) headlineLabel.setFontStyle(.Title2XLarge)
messageLabel.setFontStyle(.RegularBodySmall) messageLabel.setFontStyle(.RegularBodySmall)
spaceBetweenLabelsConstant = PaddingTwo spaceBetweenLabelsConstant = Padding.Two
} }
func stylePageHeader() { func stylePageHeader() {
headlineLabel.setFontStyle(.BoldTitleLarge) headlineLabel.setFontStyle(.BoldTitleLarge)
messageLabel.setFontStyle(.RegularBodySmall) messageLabel.setFontStyle(.RegularBodySmall)
spaceBetweenLabelsConstant = PaddingOne spaceBetweenLabelsConstant = Padding.One
} }
func styleListItem() { func styleListItem() {
@ -86,48 +82,41 @@ open class HeadlineBody: View {
super.setupView() super.setupView()
backgroundColor = .clear backgroundColor = .clear
clipsToBounds = true isAccessibilityElement = false
shouldGroupAccessibilityChildren = true
accessibilityElements = [headlineLabel, messageLabel]
let view = MVMCoreUICommonViewsUtility.commonView() addSubview(headlineLabel)
addSubview(view) addSubview(messageLabel)
NSLayoutConstraint.constraintPinSubview(toSuperview: view)
view.isAccessibilityElement = false
view.shouldGroupAccessibilityChildren = true
view.accessibilityElements = [headlineLabel, messageLabel]
view.addSubview(headlineLabel)
view.addSubview(messageLabel)
headlineLabel.setContentCompressionResistancePriority(.required, for: .vertical)
headlineLabel.setContentHuggingPriority(.required, for: .vertical) headlineLabel.setContentHuggingPriority(.required, for: .vertical)
messageLabel.setContentCompressionResistancePriority(.required, for: .vertical)
messageLabel.setContentHuggingPriority(.required, for: .vertical) messageLabel.setContentHuggingPriority(.required, for: .vertical)
view.setContentHuggingPriority(.required, for: .vertical)
headlineLabel.topAnchor.constraint(equalTo: view.topAnchor).isActive = true headlineLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true
spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant) spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant)
spaceBetweenLabels?.isActive = true spaceBetweenLabels?.isActive = true
leftConstraintTitle = headlineLabel.leftAnchor.constraint(equalTo: view.leftAnchor) NSLayoutConstraint.activate([
leftConstraintTitle?.isActive = true headlineLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
trailingAnchor.constraint(equalTo: headlineLabel.trailingAnchor),
rightConstraintTitle = view.rightAnchor.constraint(equalTo: headlineLabel.rightAnchor) messageLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
rightConstraintTitle?.isActive = true trailingAnchor.constraint(equalTo: messageLabel.trailingAnchor),
bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor)
leftConstraintMessage = messageLabel.leftAnchor.constraint(equalTo: view.leftAnchor) ])
leftConstraintMessage?.isActive = true
rightConstraintMessage = view.rightAnchor.constraint(equalTo: messageLabel.rightAnchor)
rightConstraintMessage?.isActive = true
view.bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor).isActive = true
} }
open override func updateView(_ size: CGFloat) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
setSpacing()
headlineLabel.updateView(size) headlineLabel.updateView(size)
messageLabel.updateView(size) messageLabel.updateView(size)
setSpacing()
// Provide the label additional size information to help calculate its intrinsic height.
let padding = MFStyler.defaultHorizontalPadding(forSize: size) * 2
messageLabel.preferredMaxLayoutWidth = size - padding
} }
//-------------------------------------------------- //--------------------------------------------------
@ -146,19 +135,18 @@ open class HeadlineBody: View {
// MARK: - MoleculeViewProtocol // MARK: - MoleculeViewProtocol
//-------------------------------------------------- //--------------------------------------------------
public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { public override class func estimatedHeight(with model: MoleculeModelProtocol,
return 58 _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 58 }
}
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
guard let headlineBodyModel = model as? HeadlineBodyModel else { return } guard let model = model as? HeadlineBodyModel else { return }
style(with: headlineBodyModel.style) style(with: model.style)
headlineLabel.setOptional(with: headlineBodyModel.headline, delegateObject, additionalData) headlineLabel.setOptional(with: model.headline, delegateObject, additionalData)
messageLabel.setOptional(with: headlineBodyModel.body, delegateObject, additionalData) messageLabel.setOptional(with: model.body, delegateObject, additionalData)
} }
open override func reset() { open override func reset() {