108 lines
4.1 KiB
Swift
108 lines
4.1 KiB
Swift
//
|
|
// HeadlineBody.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 7/1/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
open class HeadlineBody: ViewConstrainingView {
|
|
let headlineLabel = Label.commonLabelH2(true)
|
|
let messageLabel = Label.commonLabelB2(true)
|
|
var spaceBetweenLabelsConstant = PaddingTwo
|
|
var spaceBetweenLabels: NSLayoutConstraint?
|
|
var leftConstraintTitle: NSLayoutConstraint?
|
|
var rightConstraintTitle: NSLayoutConstraint?
|
|
var leftConstraintMessage: NSLayoutConstraint?
|
|
var rightConstraintMessage: NSLayoutConstraint?
|
|
|
|
// MARK: - MVMCoreViewProtocol
|
|
open override func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
headlineLabel.updateView(size)
|
|
messageLabel.updateView(size)
|
|
setSpacing()
|
|
}
|
|
|
|
open override func setupView() {
|
|
super.setupView()
|
|
guard subviews.count == 0 else {
|
|
return
|
|
}
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
backgroundColor = .clear
|
|
clipsToBounds = true
|
|
|
|
addSubview(headlineLabel)
|
|
addSubview(messageLabel)
|
|
|
|
headlineLabel.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
|
messageLabel.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
|
setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
|
|
|
topPin = headlineLabel.topAnchor.constraint(equalTo: topAnchor, constant: 0)
|
|
topPin?.isActive = true
|
|
|
|
spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant)
|
|
spaceBetweenLabels?.isActive = true
|
|
|
|
leftConstraintTitle = headlineLabel.leftAnchor.constraint(equalTo: leftAnchor)
|
|
leftConstraintTitle?.isActive = true
|
|
|
|
rightConstraintTitle = rightAnchor.constraint(equalTo: headlineLabel.rightAnchor)
|
|
rightConstraintTitle?.isActive = true
|
|
|
|
leftConstraintMessage = messageLabel.leftAnchor.constraint(equalTo: leftAnchor)
|
|
leftConstraintMessage?.isActive = true
|
|
|
|
rightConstraintMessage = rightAnchor.constraint(equalTo: messageLabel.rightAnchor)
|
|
rightConstraintMessage?.isActive = true
|
|
|
|
bottomPin = bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor, constant: 0)
|
|
bottomPin?.isActive = true
|
|
}
|
|
|
|
// MARK: - Constraining
|
|
public func setSpacing() {
|
|
if headlineLabel.hasText && messageLabel.hasText {
|
|
spaceBetweenLabels?.constant = spaceBetweenLabelsConstant
|
|
} else {
|
|
spaceBetweenLabels?.constant = 0
|
|
}
|
|
}
|
|
|
|
open override func setLeftPinConstant(_ constant: CGFloat) {
|
|
leftConstraintTitle?.constant = constant
|
|
leftConstraintMessage?.constant = constant
|
|
}
|
|
|
|
open override func setRightPinConstant(_ constant: CGFloat) {
|
|
rightConstraintTitle?.constant = constant
|
|
rightConstraintMessage?.constant = constant
|
|
}
|
|
|
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
|
|
let headlineJSON = json?.optionalDictionaryForKey("headline")
|
|
headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData)
|
|
let bodyJSON = json?.optionalDictionaryForKey("body")
|
|
messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
|
|
open override func reset() {
|
|
super.reset()
|
|
headlineLabel.styleH2(true)
|
|
messageLabel.styleB2(true)
|
|
spaceBetweenLabelsConstant = PaddingTwo
|
|
}
|
|
|
|
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
return 58
|
|
}
|
|
}
|
|
|