mvm_core_ui/MVMCoreUI/Molecules/StandardHeaderView.swift
Suresh, Kamlesh 9a6fd85405 merge
2019-11-27 11:05:52 -05:00

84 lines
3.6 KiB
Swift

//
// StandardHeaderView.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 2/12/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
public class StandardHeaderView: ViewConstrainingView, ModelMoleculeViewProtocol {
var line: Line?
// MARK: - MVMCoreViewProtocol
open override func updateView(_ size: CGFloat) {
super.updateView(size)
line?.updateView(size)
}
public override func setupView() {
super.setupView()
shouldSetupMoleculeFromJSON = true
updateViewVerticalDefaults = true
updateViewHorizontalDefaults = true
topMarginPadding = PaddingDefaultVerticalSpacing
bottomMarginPadding = PaddingDefaultVerticalSpacing
guard line == nil else { return }
let line = Line()
line.style = .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
self.line = line
}
// MARK: - MVMCoreUIMoleculeViewProtocol
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
// This molecule will by default handle margins.
(molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false)
(molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false)
if let separatorJSON = json?.optionalDictionaryForKey("separator") {
line?.setWithJSON(separatorJSON, delegateObject: delegateObject, additionalData: additionalData)
}
}
open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
#warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.")
//TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.
setUpWithModel(model, delegateObject, additionalData)
// This molecule will by default handle margins.
(molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false)
(molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false)
guard let headerModel = model as? HeaderModel else {
return
}
if let seperatorModel = headerModel.seperator as? LineModel {
line?.setWithJSON(seperatorModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData)
}
}
open override func reset() {
super.reset()
topMarginPadding = PaddingDefaultVerticalSpacing
bottomMarginPadding = PaddingDefaultVerticalSpacing
line?.style = .heavy
}
public override 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
}
}