StackModel
This commit is contained in:
parent
cb89795b4c
commit
3cfe5aa423
@ -12,11 +12,38 @@ import Foundation
|
||||
public static var identifier: String = "simpleStack"
|
||||
public var backgroundColor: Color?
|
||||
public var molecules: [StackItemModel]
|
||||
@Axis public var axis: NSLayoutConstraint.Axis = .vertical
|
||||
public var axis: NSLayoutConstraint.Axis = .vertical
|
||||
public var spacing: CGFloat = 16.0
|
||||
public var useStackSpacingBeforeFirstItem = false
|
||||
|
||||
public init(molecules: [StackItemModel]) {
|
||||
self.molecules = molecules
|
||||
}
|
||||
|
||||
enum StackCodingKeys: 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: StackCodingKeys.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: StackCodingKeys.self)
|
||||
try container.encodeIfPresent(molecules, forKey: .molecules)
|
||||
try container.encodeIfPresent(axis.rawValueString, forKey: .axis)
|
||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user