mvm_core_ui/MVMCoreUI/Molecules/HeaderModel.swift
Pfeil, Scott Robert f5ed509a39 renaming
2020-01-21 15:33:27 -05:00

59 lines
1.8 KiB
Swift

//
// Header.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 10/3/19.
// Copyright © 2019 Suresh, Kamlesh. All rights reserved.
//
import Foundation
@objcMembers public class HeaderModel: MoleculeContainerModel, MoleculeModelProtocol {
public static var identifier: String = "header"
public var backgroundColor: Color?
public var line: LineModel?
private enum CodingKeys: String, CodingKey {
case moleculeName
case line
case backgroundColor
}
/// Defaults to set
func setDefaults() {
if useHorizontalMargins == nil {
useHorizontalMargins = true
}
if useVerticalMargins == nil {
useVerticalMargins = true
}
if topMarginPadding == nil {
topMarginPadding = PaddingDefaultVerticalSpacing
}
if bottomMarginPadding == nil {
bottomMarginPadding = PaddingDefaultVerticalSpacing
}
line?.type = .heavy
}
public override init(with moleculeModel: MoleculeModelProtocol) {
super.init(with: moleculeModel)
setDefaults()
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
setDefaults()
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) ?? LineModel(type: .heavy)
}
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(line, forKey: .line)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
}
}