50 lines
1.7 KiB
Swift
50 lines
1.7 KiB
Swift
//
|
|
// StackModel.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 1/16/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objcMembers public class StackModel: StackModelProtocol, MoleculeModelProtocol {
|
|
public static var identifier: String = "simpleStack"
|
|
public var backgroundColor: Color?
|
|
public var molecules: [StackItemModel]
|
|
public var axis: NSLayoutConstraint.Axis = .vertical
|
|
public var spacing: CGFloat = 16.0
|
|
public var useStackSpacingBeforeFirstItem = false
|
|
|
|
public init(molecules: [StackItemModel]) {
|
|
self.molecules = molecules
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case moleculeName
|
|
case backgroundColor
|
|
case molecules
|
|
case axis
|
|
case spacing
|
|
}
|
|
|
|
required public init(from decoder: Decoder) throws {
|
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
molecules = try typeContainer.decode([StackItemModel].self, forKey: .molecules)
|
|
if let axisString = try typeContainer.decodeIfPresent(String.self, forKey: .axis), let optionalAxis = NSLayoutConstraint.Axis(rawValue: axisString) {
|
|
axis = optionalAxis
|
|
}
|
|
if let spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) {
|
|
self.spacing = spacing
|
|
}
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encodeIfPresent(molecules, forKey: .molecules)
|
|
try container.encodeIfPresent(axis.rawValueString, forKey: .axis)
|
|
try container.encodeIfPresent(spacing, forKey: .spacing)
|
|
}
|
|
}
|