mvm_core_ui/MVMCoreUI/Molecules/MoleculeHeaderView.swift
Pfeil, Scott Robert b255b1acac header updates
2020-02-24 16:53:42 -05:00

55 lines
2.0 KiB
Swift

//
// MoleculeHeaderView.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 2/12/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
public class MoleculeHeaderView: MoleculeContainer {
var line = Line()
var headerModel: MoleculeHeaderModel? {
get { return model as? MoleculeHeaderModel }
}
// MARK: - MVMCoreViewProtocol
open override func updateView(_ size: CGFloat) {
super.updateView(size)
line.updateView(size)
}
public override func setupView() {
super.setupView()
line.setStyle(.heavy)
addSubview(line)
NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true
NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true
NSLayoutConstraint.pinViewRight(toSuperview: line, useMargins: true, constant: 0).isActive = true
}
// MARK: - MVMCoreUIMoleculeViewProtocol
open override func reset() {
super.reset()
line.setStyle(.heavy)
}
// MARK: - ModelMoleculeViewProtocol
open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.setWithModel(model, delegateObject, additionalData)
guard let headerModel = headerModel else { return }
if let lineModel = headerModel.line {
line.setWithModel(lineModel, delegateObject, additionalData)
}
}
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
if let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) {
return height + PaddingDefaultVerticalSpacing + PaddingDefaultVerticalSpacing
}
return 121
}
}