re-arrage code
This commit is contained in:
parent
e59e8e3f80
commit
a5e6941c30
@ -0,0 +1,121 @@
|
||||
//
|
||||
// HeadersH2PricingTwoRows.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Lekshmi S on 16/06/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers open class HeadersH2PricingTwoRows: HeaderView {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Outlets
|
||||
//--------------------------------------------------
|
||||
public let headline = Label(fontStyle: .RegularTitleLarge)
|
||||
public let body = Label(fontStyle: .RegularMicro)
|
||||
public let subBody = Label(fontStyle: .RegularMicro)
|
||||
public let body2 = Label(fontStyle: .RegularMicro)
|
||||
public let subBody2 = Label(fontStyle: .RegularMicro)
|
||||
public let body3 = Label(fontStyle: .RegularMicro)
|
||||
public let subBody3 = Label(fontStyle: .RegularMicro)
|
||||
public let verticalLine1 = Line()
|
||||
public let verticalLine2 = Line()
|
||||
public let verticalStack1: Stack<StackModel>
|
||||
public let verticalStack2: Stack<StackModel>
|
||||
public let verticalStack3: Stack<StackModel>
|
||||
public let horizontalStack: Stack<StackModel>
|
||||
public let stack: Stack<StackModel>
|
||||
|
||||
//-------------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//-------------------------------------------------------
|
||||
public override init(frame: CGRect) {
|
||||
verticalStack1 = Stack<StackModel>.createStack(with: [body, subBody], spacing: 0)
|
||||
verticalStack2 = Stack<StackModel>.createStack(with: [body2, subBody2], spacing: 0)
|
||||
verticalStack3 = Stack<StackModel>.createStack(with: [body3, subBody3], spacing: 0)
|
||||
horizontalStack = Stack<StackModel>.createStack(with: [(view: verticalStack1, model: StackItemModel(percent: 29, verticalAlignment: .top)), (view: verticalLine1, model: StackItemModel(verticalAlignment: .top)),
|
||||
(view: verticalStack2, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .top)),
|
||||
(view: verticalLine2, model: StackItemModel(verticalAlignment: .top)),
|
||||
(view: verticalStack3, model: StackItemModel(percent: 32, verticalAlignment: .top))],
|
||||
axis: .horizontal)
|
||||
stack = Stack<StackModel>.createStack(with: [headline, horizontalStack], spacing: 8)
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
//-------------------------------------------------------
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
setDefaults()
|
||||
body.numberOfLines = 1
|
||||
body.lineBreakMode = .byTruncatingTail
|
||||
body2.numberOfLines = 1
|
||||
body2.lineBreakMode = .byTruncatingTail
|
||||
body3.numberOfLines = 1
|
||||
body3.lineBreakMode = .byTruncatingTail
|
||||
|
||||
verticalLine1.widthConstraint?.isActive = true
|
||||
verticalLine1.backgroundColor = .mvmBlack
|
||||
verticalLine2.widthConstraint?.isActive = true
|
||||
verticalLine2.backgroundColor = .mvmBlack
|
||||
|
||||
addMolecule(stack)
|
||||
stack.restack()
|
||||
verticalStack1.restack()
|
||||
verticalStack2.restack()
|
||||
verticalStack3.restack()
|
||||
horizontalStack.restack()
|
||||
setLineHeight()
|
||||
}
|
||||
|
||||
open func setDefaults() {
|
||||
headline.setFontStyle(.BoldTitleLarge)
|
||||
body.setFontStyle(.RegularMicro)
|
||||
subBody.setFontStyle(.RegularMicro)
|
||||
body2.setFontStyle(.RegularMicro)
|
||||
subBody2.setFontStyle(.RegularMicro)
|
||||
body3.setFontStyle(.RegularMicro)
|
||||
subBody3.setFontStyle(.RegularMicro)
|
||||
subBody.textColor = .mvmCoolGray6
|
||||
subBody2.textColor = .mvmCoolGray6
|
||||
subBody3.textColor = .mvmCoolGray6
|
||||
}
|
||||
|
||||
open func setLineHeight() {
|
||||
verticalLine1.heightConstraint?.isActive = false
|
||||
verticalLine1.heightConstraint = verticalLine1.heightAnchor.constraint(equalTo: body2.heightAnchor, multiplier: 1)
|
||||
verticalLine1.heightConstraint?.isActive = true
|
||||
|
||||
verticalLine2.heightConstraint?.isActive = false
|
||||
verticalLine2.heightConstraint = verticalLine2.heightAnchor.constraint(equalTo: body3.heightAnchor, multiplier: 1)
|
||||
verticalLine2.heightConstraint?.isActive = true
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
// MARK: - Molecule
|
||||
//------------------------------------------------------
|
||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let model = model as? HeadersH2PricingTwoRowsModel else { return }
|
||||
headline.set(with: model.headline, delegateObject, additionalData)
|
||||
verticalStack1.updateContainedMolecules(with: [model.body, model.subBody], delegateObject, additionalData)
|
||||
verticalStack2.updateContainedMolecules(with: [model.body2, model.subBody2], delegateObject, additionalData)
|
||||
verticalStack3.updateContainedMolecules(with: [model.body3, model.subBody3], delegateObject, additionalData)
|
||||
setLineHeight()
|
||||
}
|
||||
|
||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return 121
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
setDefaults()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
//
|
||||
// HeadersH2PricingTwoRowsModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Lekshmi S on 16/06/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class HeadersH2PricingTwoRowsModel: HeaderModel, MoleculeModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
public static var identifier: String = "headerH2TwoRows"
|
||||
public var headline: LabelModel
|
||||
public var body: LabelModel
|
||||
public var subBody: LabelModel?
|
||||
public var body2: LabelModel
|
||||
public var subBody2: LabelModel?
|
||||
public var body3: LabelModel
|
||||
public var subBody3: LabelModel?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
public init(headline: LabelModel, body: LabelModel, subBody: LabelModel? = nil, body2: LabelModel, subBody2: LabelModel? = nil, body3: LabelModel, subBody3: LabelModel? = nil) {
|
||||
self.headline = headline
|
||||
self.body = body
|
||||
self.subBody = subBody
|
||||
self.body2 = body2
|
||||
self.subBody2 = subBody2
|
||||
self.body3 = body3
|
||||
self.subBody3 = subBody3
|
||||
super.init()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
public override func setDefaults() {
|
||||
super.setDefaults()
|
||||
subBody?.attributes = [LabelAttributeStrikeThroughModel(0, subBody?.text.count ?? 0)]
|
||||
subBody2?.attributes = [LabelAttributeStrikeThroughModel(0, subBody2?.text.count ?? 0)]
|
||||
subBody3?.attributes = [LabelAttributeStrikeThroughModel(0, subBody3?.text.count ?? 0)]
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case headline
|
||||
case body
|
||||
case subBody
|
||||
case body2
|
||||
case subBody2
|
||||
case body3
|
||||
case subBody3
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Codec
|
||||
//--------------------------------------------------
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
|
||||
body = try typeContainer.decode(LabelModel.self, forKey: .body)
|
||||
subBody = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subBody)
|
||||
body2 = try typeContainer.decode(LabelModel.self, forKey: .body2)
|
||||
subBody2 = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subBody2)
|
||||
body3 = try typeContainer.decode(LabelModel.self, forKey: .body3)
|
||||
subBody3 = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subBody3)
|
||||
try super.init(from: decoder)
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encode(headline, forKey: .headline)
|
||||
try container.encode(body, forKey: .body)
|
||||
try container.encodeIfPresent(subBody, forKey: .subBody)
|
||||
try container.encode(body2, forKey: .body2)
|
||||
try container.encodeIfPresent(subBody2, forKey: .subBody2)
|
||||
try container.encode(body3, forKey: .body3)
|
||||
try container.encodeIfPresent(subBody3, forKey: .subBody3)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user