64 lines
2.1 KiB
Swift
64 lines
2.1 KiB
Swift
//
|
|
// Header.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 3/6/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
open class HeaderView: Container {
|
|
public let line = Line()
|
|
|
|
/// Convenience for doing some default setting
|
|
open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
|
|
|
|
var headerModel: HeaderModel? {
|
|
get { return model as? HeaderModel }
|
|
}
|
|
|
|
/// Convenience function to add a molecule to the view.
|
|
open func addMolecule(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {
|
|
addSubview(molecule)
|
|
containerHelper.constrainView(molecule)
|
|
self.molecule = molecule
|
|
}
|
|
|
|
// MARK: - MVMCoreViewProtocol
|
|
open override func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
line.updateView(size)
|
|
molecule?.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)
|
|
molecule?.reset?()
|
|
}
|
|
|
|
// MARK: - ModelMoleculeViewProtocol
|
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
super.set(with: model, delegateObject, additionalData)
|
|
guard let headerModel = headerModel else { return }
|
|
if let lineModel = headerModel.line {
|
|
line.set(with: lineModel, delegateObject, additionalData)
|
|
}
|
|
}
|
|
|
|
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
|
return PaddingDefaultVerticalSpacing + PaddingDefaultVerticalSpacing
|
|
}
|
|
}
|